Lesson - 5
Algorithms and Flowchart
Flow charts
• What is chart?
• Chart is a pictorial representation of data.
• What is flowchart?
• A flowchart is a picture of a problem solving process.
• A flowchart gives a step by step procedure for solution of a problem.
Flowchart
• A flowchart is a picture of a problem solving process.
• A flowchart gives a step-by-step procedure for solution of a problem.
• Elements of flowchart:
• Various geometrical shaped boxes represent the steps of the solution.
• The boxes are connected by directional arrows to show the flow of the
solution.
• Flowcharts are used to:
• Specify the method of solving a problem.
• Plan the sequence of a computer program.
• Communicate ideas and solutions.
Algorithm
• What is algorithm?
• Algorithm is a logical sequence of discrete steps that describe a complete
solution to a given problem in a finite amount of time.
• Characteristics of a good Algorithm
• Correctness of Algorithm – whether the algorithm is yielding correct results
with the set of inputs.
• Efficiency of an Algorithm – How fast it is , how simple or complex steps it
uses to solve the problem.
• Uses of Algorithm
• Algorithms are used in all types of programming. There are standard, efficient
algorithms available for a variety of tasks. Example, Search Engine, Weather
forecasting, Sorting, Pattern Recognition etc.
Developing an Algorithm
• Step 1: Obtain a description of the problem – Detailed description aids to better solution.
• Step 2: Analyze the problem – Analyze to figure out what is to be calculated or produced for a given set
of input conditions/ values. Check if any data is dependent on other data or not.
• Step 3: Develop a high-level algorithm – Come up with and develop a high-level algorithm that includes
the major part of a solution.
• Step 4: Refine the algorithm by adding more detail – Refine the algorithm and include minor steps.
• Step 5: Review and test the algorithm – Review the algorithm’s steps carefully and test it with the
sample test it with the sample set of values whether it producing correct result or not.
Geometrical shapes used in flowcharts:
- Ellipse used to show start and end of procedure in flowchart.
- Parallelogram is used to show input and output in problem solving
process
- Rectangle is used to show process.
- Arrow is used to show flow and step in sequence.
Yes
- A diamond shape with two branches is used to show the decision making
No step in a flowchart.
Discuss steps to add two number
Start
A=125
B=250
Sum=125+250
Sum=375
End
Draw a flowchart and develop an algorithm to
show Addition of two numbers.
Start Start Algorithm
A=250 Read A • Step 1: start
• Step 2: Enter two numbers
B=125
Read B
• Step 3 : Add one number from the
Sum=250+125 Sum=A+B other number.
• Step 4: Display result of the Addition.
Sum=375 Print Sum • Step 5: End
End End
Flow
chart
Draw a flowchart to show Addition of two
numbers.
Start
Flow
chart Read A
Read B
Sum=A+B
Print Sum
End
Geometrical shapes used in flowcharts:
No
Question
Yes
Discuss steps to add two number
Start Start
A=125 Read A
B=250 Read B
Sum=125+250 Sum=A +B
Sum=375 Print Sum
End
End
Write an algorithm and Draw a flowchart to
find Maximum from two numbers
Algorithm Start
1.Start Read A
2.Read two numbers
3.Compare both the Read B
numbers. No Print B is
IF A>B
4.Display the maximum Yes
greater
number from the given Print A is
Greater
two numbers.
5.End End