0% found this document useful (0 votes)
33 views

CC 204 Module

The document provides an introduction to data structures and algorithms. It defines key concepts like variables, data types, data structures and algorithms. It also discusses abstract data types and different types of data structure analysis. The overall goal is to help students understand fundamental concepts related to data structures and algorithms.

Uploaded by

JieL 지엘
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

CC 204 Module

The document provides an introduction to data structures and algorithms. It defines key concepts like variables, data types, data structures and algorithms. It also discusses abstract data types and different types of data structure analysis. The overall goal is to help students understand fundamental concepts related to data structures and algorithms.

Uploaded by

JieL 지엘
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Module in CC 204:

Data Structure and Algorithm

Grace Lhyn R. Legaste

Notes to the Students


This module is a part of the series of Modules for flexible learning spearheaded by
the Office of the Director of Instruction and the Center for Teaching Excellence, West
Visayas State University.
This is meant for the course CC 204 - Data Structure and Algorithm
Computer Programming is a creative process with no complete set of rules for
creating a program. It can develop a persons creativity and problem solving skills.
This module have the following set of lessons or topics:
Unit 1: Review of the Basic Concept of Java
Unit 2: Java Arrays
Unit 3: Creating Classes and Methods
Unit 4: Closer Look at Methods and Classes
Unit 5: GUI Basics
The learning outcomes for CC 204, specified below are unpacked by the specific
objectives of each lessons. Generally, at the end of this module, you would have:
1. Analyze complex problems, and identify and define the computing requirements
needed to design an appropriate solution
2. Apply computing and other knowledge domains to address real world problems.
3. Design and develop computing solutions using a system level perspective.
4. Utilize modern computing tools.

The lesson will unfold in the following sequence:

Acquire New Knowledge. This is where lesson is presented. It may have


several topics as stipulated in the specific objectives.

Apply your knowledge. In this part, you will practice what you have
learned.
Assess your knowledge. You will be tested here and you will be able to
know the gaps in your understanding in this lesson. If you are not satisfied
with the feedback, you may then go back to some point that you may have
missed.

References. List down the resources and links from which the content of
the lesson was based from. These may take the form of books, internet
sites, blogs, videos, photographs, animation, PowerPoint Presentations,
icons, etc.

Directions are found inside each lesson that will tell you how long you are going to
work on this module. All formative activities must be answered and counter-checked
with the feedback attached. Honesty is a school policy. Be serious about the learning
activities you are working on. It will define who you are and what you will become in the
future. Pre-test and post-test must be completed as well. At the end of the semester or
as instructed otherwise, you are to submit this module to your subject professor.
Inquiries on some points not fully understood will be made online via Google Classroom
in a scheduled encounter. This module is a self-contained learning kit with instructions
that will guide you to the end.
The following are my personal contact information just in case you needed to
contact me immediately:
Mobile Number: 0921-718-4865
E-mail Address: [email protected]

You are now ready to begin. Happy learning and happy coding.

Unit 1: Introduction to Data Structures

a) Variable, Data types, Data Structures


b) What is an Algorithm?
Objectives:
At the end of the unit, you must have:
a. Defined Variable, Data types and data Structures;
b. Understand algorithms;

Acquire new knowledge


Lesson Proper

Lesson 1: Variables, Data Types and Data Structure

Variables and Data Types


As we’ve learned in the previous lesson (Computer Programming 1 & 2), variable
serves as a “container” that holds values that are used in a Java Program.

In programming, a data type is a set of data with predefined value. We also have a
System-defined data types or primitive data types and user defined data types.

System-Defined Data Types (Primitive Data Types)


This are data types that are defined by the system which includes byte, int, short, long,
float, double, char, boolean. The number of bits allocated for each primitive data type
depends on the programming languages, the compiler and the operating system.

User Defined Data Types


If the system-defined data types are not enough, then most programming languages
allow the users to define their own data types, called user defined data types. Good
examples of user defined data type is the classes in Java. For example, in the snippet
below, we are combining many system-defined data types and calling the user defined
data type by the name “newType”. This gives more flexibility and comfort in dealing with
computer memory.

Data Structures

Based on the discussion above, once we have data in variables, we need some
mechanism for manipulating that data to solve problems. Data structure is a particular
way of storing and organizing data in a computer so that it can be used efficiently. A
data structure is a special format for organizing and storing data. General data structure
types include arrays, files, linked lists, stacks, queues, trees, graphs and so on.

Depending on the organization of the elements, data structures are classified into two
types:
1) Linear data structures: Elements are accessed in a sequential order but it is not
compulsory to store all elements sequentially. Examples: Linked Lists, Stacks and
Queues.
2) Non – linear data structures: Elements of this data structure are stored/accessed in a
non-linear order. Examples: Trees and graphs.

Abstract Data Types (ADTs)

Before defining abstract data types, let us consider the different view of system-defined
data types. We all know that, by default, all primitive data types (int, float, etc.) support
basic operations such as addition and subtraction. The system provides the
implementations for the primitive data types. For user-defined data types we also need
to define operations. The implementation for these operations can be done when we
want to actually use them. That means, in general, user defined data types are defined
along with their operations.
To simplify the process of solving problems, we combine the data structures with their
operations and we call this Abstract Data Types (ADTs). An ADT consists of two parts:
1. Declaration of data
2. Declaration of operations

Commonly used ADTs include: Linked Lists, Stacks, Queues, Priority Queues, Binary
Trees, Dictionaries, Disjoint Sets (Union and Find), Hash Tables, Graphs, and many
others. For example, stack uses LIFO (Last-In-First-Out) mechanism while storing the
data in data structures. The last element inserted into the stack is the first element that
gets deleted. Common operations of it are: creating the stack, pushing an element onto
the stack, popping an element from stack, finding the current top of the stack, finding
number of elements in the stack, etc.

While defining the ADTs do not worry about the implementation details. They come into
the picture only when we want to use them. Different kinds of ADTs are suited to
different kinds of applications, and some are highly specialized to specific tasks.

Lesson 2: What is an Algorithm?


Let us consider the problem of preparing an omelette. To prepare an omelette, we
follow the steps given below:
1) Get the frying pan.
2) Get the oil.
a) Do we have oil?
i. If yes, put it in the pan.
ii. If no, do we want to buy oil?
a) If yes, then go out and buy.
b) If no, we can terminate.
3) Turn on the stove, etc..

What we are doing is, for a given problem (preparing an omelette), we are providing a
step-by- step procedure for solving it. The formal definition of an algorithm can be
stated as:
An algorithm is the step-by-step unambiguous instructions to solve a given
problem.

In the traditional study of algorithms, there are two main criteria for judging the merits
of algorithms: correctness (does the algorithm give solution to the problem in a finite
number of steps?) and efficiency (how much resources (in terms of memory and time)
does it take to execute the steps).

Note: We do not have to prove each step of the algorithm.

Why the Analysis of Algorithm?

To go from city “A” to city “B”, there can be many ways of accomplishing this: by flight,
by bus, by train and also by bicycle. Depending on the availability and convenience, we
choose the one that suits us. Similarly, in computer science, multiple algorithms are
available for solving the same problem (for example, a sorting problem has many
algorithms, like insertion sort, selection sort, quick sort and many more). Algorithm
analysis helps us to determine which algorithm is most efficient in terms of time and
space consumed.

The goal of the analysis of algorithms is to compare algorithms (or solutions) mainly in
terms of running time but also in terms of other factors (e.g., memory, developer
effort, etc.)

Running Time Analysis is the process of determining how processing time increases
as the size of the problem (input size) increases. Input size is the number of elements in
the input, and depending on the problem type, the input may be of different types. The
following are the common types of inputs.
 Size of an array
 Polynomial degree
 Number of elements in a matrix
 Number of bits in the binary representation of the input
 Vertices and edges in a graph.

Types of Analysis
To analyze the given algorithm, we need to know with which inputs the algorithm takes
less time (performing wel1) and with which inputs the algorithm takes a long time. We
have already seen that an algorithm can be represented in the form of an expression.
That means we represent the algorithm with multiple expressions: one for the case
where it takes less time and another for the case where it takes more time.

In general, the first case is called the best case and the second case is called the worst
case for the algorithm. To analyze an algorithm we need some kind of syntax, and that
forms the base for asymptotic analysis/notation. There are three types of analysis:
 Worst case
 Defines the input for which the algorithm takes a long time (slowest time to
complete).
 Input is the one for which the algorithm runs the slowest.
 Best case
 Defines the input for which the algorithm takes the least time (fastest time to
complete).
 Input is the one for which the algorithm runs the fastest.
 Average case
 Provides a prediction about the running time of the algorithm.
 Run the algorithm many times, using many different inputs that come from
some distribution that generates these inputs, compute the total running time
(by adding the individual times), and divide by the number of trials.
 Assumes that the input is random.

Apply your knowledge. In this part, you will practice what you have
learned.
Assess your knowledge. You will be tested here and you will be able to
know the gaps in your understanding in this lesson. If you are not satisfied
with the feedback, you may then go back to some point that you may have
missed.
Unit 2: Linked Lists, Stacks and Queues
Objectives:
At the end of the unit, you must have:
c.

Acquire new knowledge


Lesson Proper

Lesson 1: Linked Lists


What is Linked List?

A linked list is a data structure used for storing collections of data. A linked list has the
following properties.
 Successive elements are connected by pointers
 The last element points to NULL
 Can grow or shrink in size during execution of a program
 Can be made just as long as required (until systems memory exhausts)
 Does not waste memory space (but takes some extra memory for pointers). It
allocates memory as list grows.

Why linked lists?


Linked list is a linear Data Structure like an Array.
Array has fixed size, but Linked list can dynamically increase its size to overcome this
limitation.
We can perform operations like insertion, deletion with ease unlike array where we have
to shift all the element after the operation.

You might also like