Professional Documents
Culture Documents
Learning Objectives
In this chapter you will learn about:
Algorithm
Refers to the logic of a program and a step-by-step description of how
to arrive at the solution of a given problem
In order to qualify as an algorithm, a sequence of instructions must
have following characteristics:
Each and every instruction should be precise and unambiguous
Each instruction should be such that it can be performed in a finite
time
One or more instructions should not be repeated infinitely. This
ensures that the algorithm will ultimately terminate
After performing the instructions, that is after the algorithm
terminates, the desired results must be obtained
Amity School of Engineering & Technology
Step 8: Stop.
Amity School of Engineering & Technology
Representation of Algorithms
As programs
As flowcharts
As pseudocodes
Flowchart
Flowchart is a pictorial representation of an algorithm
Uses symbols (boxes of different shapes) that have
standardized meanings to denote different types of
instructions
Actual instructions are written within the boxes
Boxes are connected by solid lines having arrow marks
to indicate the exact sequence in which the instructions
are to be executed
Process of drawing a flowchart for an algorithm is called
flowcharting
Amity School of Engineering & Technology
Yes A=B
I=?
= 0 =1 = 2 = 3 = 4 =5 = Other
Percentage = Total / 10
Stop
Amity School of Engineering & Technology
Percentage = Total / 10
Count = 0
Percentage = Total/10
Yes
Stop
Amity School of Engineering & Technology
Yes
Is Rollno = 0000000?
Generalized flowchart
No for the solution of
Add marks of all subjects Example 4 using the
Stop
giving Total concept of trailer
record. Here the
process loop is
Percentage = Total / 10 terminated by detecting
a special non-data
record.
Write output data
Amity School of Engineering & Technology
Yes
Is Rollno = 9999999?
Write Count
No
Add marks of all subjects giving Total Stop
Percentage = Total/10
No
Is Percentage = > 30?
Add 1 to Count
Amity School of Engineering & Technology
Count = 0
Yes 2
Is Sexcode = Z?
No
1 No Is Sexcode = F?
Yes
Add marks of all subjects
giving Total
Percentage = Total / 10
3
Amity School of Engineering & Technology
No
1 Is Percentage = > 45?
Yes
2
No
1 Is Percentage < 60?
Write Count
Yes
Write output data
Stop
Add 1 to Count
1
Amity School of Engineering & Technology
Levels of Flowchart
Flowchart that outlines the main segments of a program
or that shows less details is a macro flowchart
Part of a macro 1
flowchart
I=1 A micro
Flowchart
Total = 0
No
Is I > 10?
Yes
1
Amity School of Engineering & Technology
Flowcharting Rules
First chart the main line of logic, then incorporate detail
Flowcharting Rules
(contd…)
Be consistent in using names and variables in
the flowchart
Advantages of Flowchart
Better Communication
Proper program documentation
Efficient coding
Systematic debugging
Systematic testing
Amity School of Engineering & Technology
Limitations of Flowchart
Flowcharts are very time consuming and laborious to
draw (especially for large complex programs)
Redrawing a flowchart for incorporating changes/
modifications is a tedious task
There are no standards determining the amount of
detail that should be included in a flowchart