0% found this document useful (0 votes)
88 views24 pages

CPE121 - Chapter01 - Introduction To Data Structures and Algorithm

This document provides an introduction to data structures and algorithms. It defines key terms like data types, data structures, abstract data types and classifications of data structures. The objectives and topics covered in the lesson are outlined. Examples of primitive and non-primitive data structures are given. Key criteria for algorithms are listed. Activities for students to practice algorithms are provided at the end.

Uploaded by

Jiji Macaso
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
88 views24 pages

CPE121 - Chapter01 - Introduction To Data Structures and Algorithm

This document provides an introduction to data structures and algorithms. It defines key terms like data types, data structures, abstract data types and classifications of data structures. The objectives and topics covered in the lesson are outlined. Examples of primitive and non-primitive data structures are given. Key criteria for algorithms are listed. Activities for students to practice algorithms are provided at the end.

Uploaded by

Jiji Macaso
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 24

CPE 121

Data Structures and Algorithm

Introduction to
Data Structures
and Algorithm
WMSU Chapter 01

Engr. Monira O. Kamlian, MEngEd-ICT


College of Engineering
Department of Computer Engineering

For instructional purposes only


Objectives
At the end of the lesson, you should be able to:
• define data structures and abstract data type;
• explain the importance of data structures in
programming;
• classify the types of data structures;
• identify the properties of an algorithm; and
• write an algorithm for a certain problem.

For instructional purposes only


Topic Outline
• Definition of Data Type, Data Structures and
Abstract Data Type (ADT)
• Classification of Data Structures
• Algorithms

For instructional purposes only


“I will, in fact, claim that the difference
between a bad programmer and a good one is
whether he considers his code or his data
structures more important. Bad programmers
worry about the code. Good programmers
worry about data structures and their
relationships.”
-- Linus Torvalds

For instructional purposes only


Data type
• Refers to the to the kind of data that variables
can assume, hold or take on in a programming
language and for which operations are
automatically provided.

Table 1.
Primitive data types in Java.
For instructional purposes only
Abstract Data Type (ADT)
• ADT is a mathematical model with a collection
of operations defined on the model.
• It specifies the type of data stored.
• It specifies what its operations do but not how
it is done.
• In Java, for example, ADT can be expressed
with an interface, which contains just a list of
methods.
For instructional purposes only
Abstract Data Type (ADT)…
• For example, the following is an interface of
the ADT stack

For instructional purposes only


Data Structures
• The way the data is organized in the
computer’s memory.
• It is the manner of collecting and organizing
the data so that it can be accessed in the most
effective way.
• It is the implementation of ADT in terms of the
data types or other data structures.
– In Java, for instance, a data structure is modeled
by a class.
For instructional purposes only
Classification of Data Structures

Figure 1. Classification of Data Structures For instructional purposes only


Primitive Data Structures
• considered to be the building blocks for
data manipulation
– these are the basic data types which are pre-
defined in the programming language and the
user cannot change it.
– These data types use single values which
specify the size and type of the data use
– Examples:
• Integer, Float, Double, Character, Pointer

For instructional purposes only


Non-Primitive Data Structures
• more complex data structures and are
derived from primitive data structures.
– Linear Data structures
• if its elements are connected linearly in logical or
sequential manner in memory location
• arrays, list, stacks, queues
– Non-linear
• shows a hierarchical relationship
• tress, graphs

For instructional purposes only


Algorithms
• a finite set of instructions that specify a
sequence of operations to be carried out in
order to solve a specific problem or class
of problems.

For instructional purposes only


For instructional purposes only
Symbols used in
Flowcharting

For instructional purposes only


Getting the average of 3 numbers

1.Start 1. Start 1. start


2.Input value of x 2. Input A 2. set first number a
3.Input value of y 3. Input B 3. set second number b
4.Input value of z 4. Input C 4. set third number c
5.sum=x+y+z 5. D = A + B + C / 5. get the sum and divide it by 3 to get the average
6.avg=sum/3 3 6. end
7.output "avg" 6. Output D
8.End 7. End
1. Start
2. Output "please input 3 number"
1) declare variables n1, n2, n3, & sum as integer. avg as float
2) initialize values as 0
3. Input num x
3) enter the values 4. Input num y
4) add the numbers and store in variable sum 5. Input num z
5) print sum 6. Process ( int num x + int num y + int z = total)
6) divide the sun of the numbers by 3 and store in variable avg 7. Process (Total / 3 = average)
7) print avg 8. Output "the average is:"
9. Output average
10. End
1. Start
2. Declare x, y, z as integers; avg as float
3. Enter value for x, y, and z
4. Add the three numbers (x + y + z)
5. Divide the sum of the three numbers by 3
6. Output avg For instructional purposes only
7. End
Getting the average of 3 numbers

For instructional purposes only


Activity #1
What does this algorithm represents?
1. BEGIN
2. NUMBER counter, sum=0, num
3. FOR counter=1 TO 10 STEP 1 DO
4. OUTPUT "Enter a Number"
5. INPUT num
6. IF num % 2 == 0 THEN
7. sum=sum+num
8. ENDIF
9. ENDFOR
10. OUTPUT sum
11.
12. END

For instructional purposes only


Activity #2
Create an algorithm to solve the given problem

• A program that computes the sum of the


two given integer values. If the two values
are the same, then return triple their sum.

For instructional purposes only


Criteria for Algorithms
Every algorithm must satisfy the following criteria:
 Input - There are zero or more quantities which are externally
supplied.
 Output - At least one quantity is produced.
 Definiteness - Each instruction must be clear and unambiguous.
 Finiteness - If we trace out the instructions of an algorithm, then
for all cases, the algorithm will terminate after a finite number of
steps.
 Effectiveness - Every instruction must be sufficiently basic that it
can, in principle, be carried out by a person using only pencil and
paper. It is not enough that operation be definite as in #3, but
must it must be also feasible.
For instructional purposes only
Let’s try to examine the code below.

• Input = There is no user input since the data from where to get the minimum is
already in the program.
• Output = The minimum value from the given set of input elements.
• Definiteness = Each step in the program is precisely defined.
• Finiteness = The declaration, the for loop and the statement to output will all take
a finite time to execute.
• Effectiveness = when run, it returns the minimum among the values in the array
so it is said to be effective. For instructional purposes only
Assignment #2
Examine the given code below. Determine if the code adheres
to the criteria for algorithms. Discuss each criteria.

• Input ?
• Output ?
• Definiteness ?
• Finiteness ?
• Effectiveness ? For instructional purposes only
Activity #5
What does this algorithm represents?
1. Input the number of the integers to compare; call it N.
2. Input the first integer; call it NUM1.
3. Input the second integer; call it LARGE.
4. Set up a counter representing the number of integers that
have been read; call it COUNT. Set COUNT to 2.
5. Compare NUM1 with LARGE; if NUM1 is greater than
LARGE, set LARGE to NUM1.
6. If COUNT equals N, display the value of LARGE and exit.
Otherwise, increment COUNT by 1 and input the next
integer to be compared.
7. Return to Step 5.
For instructional purposes only
• Activity #1 = done
• Activity #2 = due Aug 24, 2022
• Activity #3,4,5 = due Aug 26, 2022 not
later than 2PM

For instructional purposes only


References:
• Data Structures. JEDI Course Notes
• Goodric ,M, Tamassia,R. Data Structures in
Algorithms in JAVA. 4th edition.

For instructional purposes only

You might also like