Chapter 1
Chapter 1
Science
Chapter 1
Data Structure
Learning outcomes:
Data vs Information.
Definition of Data Structure.
Types of Data Structure.
Algorithm
Pseudo code
Flow Chart
Data Structure
Data vs Information
Data:
Raw collection facts and figures. such as number words measurements or just description of
things.
Data can be qualitative or quantitative
Information :
when the data are processed, organized, structured or presented in a given context to make
them use full they are called information.
The processed form of data is known as information.
Data Structure
Environment setup
In this course we are going to implement data structure in C++ language.
Here, all the programs of the data structure will be shown using C++. So for that,
you need to install one of the following IDE.
Turbo C++
Borland C++
Dev C++
Falcon C++
Visual C++
Data Structure
Algorithms
Algorithm is a step by step procedure to solve a given problem.
An algorithm is a finite set of steps defining the solution of a particular problem.
Algorithm should be written in such a way that it can be used in different
programming languages.
Remember algorithm is:
Platform independent
Can be implemented in any programming language
Data Structure
Features of Algorithm
Algorithm notation
Algorithm Name
Should be in capital form
Meaningful
Parameters
Should be enclosed in parenthesis ( )
Introductory Comment
Description and purpose of an algorithm
Steps
Finite steps
Data
Structure
Algorithm notation
Comments Output statement
Each step start with a comment Write
Enclose in [ ] cout (if using C++)
.Define the purpose of step
Finish
Input Statements
Exit (Used in main
Read
cin (if using C++) algorithm)
Return (Used in sub
algorithm)
Data Structure
Example
Algorithm LARGE(No1, No2, lar)
{This algorithm is used to read two numbers and print the largest}
Step-1 [ Read numbers No1 and No2]
Read(No1,No2)
Step-2 [Find the largest]
if (No1 > No2) then lar = No1
else
lar = No2
end if
Step-3 [Display the Result ]
Write(lar)
Step-4 [Finish]
Exit
Data Structure
Example description
Algorithm Name (Large )
Parameters (No1, No2 and lar)
Input and Output Statement(Read, Write)
Selection Statement (if-else)
Comments (enclosed in [ ] before start of each step)
Introductory comments (enclosed in { } )
Finish (exit)
Data Structure
Pseudo Code
Is one of the methods that could be used to represent an algorithm.
Pseudocode is an informal language that helps programmers develop algorithms.
It is not written in specific syntax and cannot be executed in a computer.
It is written in symbolic code which must be translated into a programming language
before it can be executed.
is a methodology that allows the programmer to represent the implementation of an
algorithm.
Data Structure
Advantages of Pseudocode
Improves the readability of any approach. It’s one of the best approaches to start
implementation of an algorithm.
Acts as a bridge between the program and the algorithm.
The main goal of a pseudo code is to explain what exactly each line of a program
should do.
It can be written easily.
It can be read and understood easily
Data Structure
Example
IF you are happy THEN
Smile
ELSE
Cry
ENDIF
Data Structure
Example
Input color
Case color of
Red : print “red”
Green : print “green”
Blue : print “blue
Other
Print “Not Match”
Endcase
Data Structure
Example
If student's grade is greater than or equal to 55
Print "passed"
else
Print "failed"
Data Structure
Example
compute the area of a rectangle
Get the length, l, and width, w
Compute the area = l*w
Display the area
Data Structure
Flow chart
A flowchart is a diagram that depicts the flow of a program.
Flowchart is a type of diagram that represents an algorithm or process.
The pictorial representation of the programs or the algorithm is known as flowcharts.
The purpose of using flowcharts is to graphically present the logical flow of data in the
system and defining major phases of processing along with the various media to be
used.
Data Structure
Terminals
represented by rounded rectangles
indicate a starting or ending point
START
END
Data Structure
Flow line
represented by arrow.
Used to Indicates the relationship between shapes.
Data Structure
Input/Output Operations
represented by parallelograms
indicate an input or output operation
Print “Enter a
number for x”; Read x
Data Structure
Processes
represented by rectangles
indicates a process such as a mathematical computation or variable assignment.
Multiply x & y.
Data Structure
Decision
Use for asking question that can have either TRUE or FALSE as an answer.
X>Y
Data Structure
Algorithm
Flowchart
Add 10 with 20
1. Start
2. Initialize sum=0 (process)
3. Enter the numbers (I/O)
4. Add them and store the result in sum (process)
5. Print (I/O)
6. End
Data Structure
Review Question:
What is Data and Information?
What is Data Structure?
Explain types of Data Structure?
What is Algorithm?
What is Pseudo Code and Flow Chart?
Write Algorithm for any program?
Write algorithm to calculate the sum and average of two numbers?
Create a Flow chart to determine whether the student passed the exam or not?
Create a Flow chart to determine number N is Even or Odd?
Data Structure
Thanks You
For Your Patience