Algorithm and Flow Chart
Algorithm and Flow Chart
Chart
Engr. Klint Ian V. Austero
Silliman University
College of Engineering and Design
CONTENT
• Introduction
• Problem Solving
• Algorithm
• Examples of Algorithm
• Properties of an Algorithm
• Flow Chart
• Flow Chart Symbols
• Some Flowchart Examples
• Advantages of Flow Charts
Silliman University
College of Engineering and Design
Introduction
• Intelligence is one of the key
characteristics which differentiate a
human being from other living creatures
on the earth. Basic intelligence covers
day to day problem solving and making
strategies to handle different situations
which keep arising in day to day life.
Silliman University
College of Engineering and Design
Problem Solving
• Can you think of a day in your life which
goes without problem solving?
All activities in human life involve some kind
of decision and problem solving.
Silliman University
College of Engineering and Design
Algorithm
Now, if we take definition of algorithm as: “A sequence
of activities to be processed for getting desired output
from a given input.” Then we can say that:
1. Getting specified output is essential after algorithm is
executed.
2. One will get output only if algorithm stops after finite
time.
3. Activities in an algorithm to be clearly defined in other
words for it to be unambiguous.
Silliman University
College of Engineering and Design
Algorithm
Now, if we take definition of algorithm as: “A sequence
of activities to be processed for getting desired output
from a given input.” Then we can say that:
1. Getting specified output is essential after algorithm is
executed.
2. One will get output only if algorithm stops after finite
time.
3. Activities in an algorithm to be clearly defined in other
words for it to be unambiguous.
Silliman University
College of Engineering and Design
Algorithm Examples
While writing algorithms we will use following symbol for
different operations:
Silliman University
College of Engineering and Design
Algorithm Examples
Problem 1: Find the area of a Circle of radius r.
Silliman University
College of Engineering and Design
Algorithm Examples
Problem 2: Write an algorithm to read two numbers and find their sum.
Inputs to the algorithm: First num1.
Second num2.
Expected output: Sum of the two numbers.
Silliman University
College of Engineering and Design
Algorithm Examples
Problem 3: Convert temperature Fahrenheit to Celsius
Silliman University
College of Engineering and Design
TYPES of ALGORITHM
1. Sequence
2. Branching (Selection)
3. Loop (Repetition)
Silliman University
College of Engineering and Design
BRANCH Example
Problem 1: Write algorithm to find the greater
number between two numbers
Step1: Start
Step2: Read/input A and B
Step3: If A greater than B then C=A
Step4: If B greater than A then C=B
Step5: Print C
Silliman UniversityStep6: End
College of Engineering and Design
BRANCH Example
Problem 2: Write algorithm to find the result of equation:
Step1: Start
Step2: Read/input X
Step3: If X Less than zero then F=-X
Step4: If X greater than or equal zero then F=X
Step5: Print F
Step6: End
Silliman University
College of Engineering and Design
BRANCH Example
Problem 3: Write algorithm to find the largest value
of any three numbers.
Silliman University
College of Engineering and Design
BRANCH Example
Problem 3: Write algorithm to find the largest value of any three
numbers.
Step1: Start
Step2: Read/input A,B and C
Step3: If (A>=B) and (A>=C) then Max=A
Step4: If (B>=A) and (B>=C) then Max=B
Step5: If (C>=A) and (C>=B) then Max=C
Step6: Print Max 7
Step7: End
Silliman University
College of Engineering and Design
LOOP Examples
Problem 1: An algorithm to calculate even numbers
between 0 and 99.
Step1: Start
Step2: I ← 0
Step3: Write I in standard output
Step4: I ← I+2
Step5: If (I <=98) then go to line 3
Step6: End
Silliman University
College of Engineering and Design
LOOP Examples
Problem 2: Design an algorithm which gets a natural value, n, as its input
and calculates odd numbers equal or less than n. Then write them in the
standard output:
Step1: Start
Step2: Read n
Step3: I ← 1
Step4: Write I
Step5: I ← I + 2
Step6: If ( I <= n) then go to line 4
Step7: End
Silliman University
College of Engineering and Design
LOOP Examples
Problem 3: Design an algorithm which generates
even numbers between 1000 and 2000 and then prints
them in the standard output. It should also print total
sum:
Silliman University
College of Engineering and Design
LOOP Examples
Problem 3: Design an algorithm which generates even numbers between 1000
and 2000 and then prints them in the standard output. It should also print total sum:
Step1: Start
Step2: I ← 1000 and S ← 0
Step3: Write I
Step4: S ← S + I
Step5: I ← I + 2
Step6: If (I <= 2000) then go to line 3 else go to line 7
Step7: Write S
Step8: End
Silliman University
College of Engineering and Design
PROPERTIES OF ALGORITHM
• Finiteness:
• An algorithm must always terminate after a finite number of steps. It
means after every step one reach closer to solution of the problem and
after a finite number of steps algorithm reaches to an end point.
• Definiteness:
• Each step of an algorithm must be precisely defined. It is done by well
thought actions to be performed at each step of the algorithm. Also the
actions are defined unambiguously for each activity in the algorithm.
• Input:
• Any operation you perform need some beginning value/quantities
associated with different activities in the operation. So the
value/quantities are given to the algorithm before it begins.
Silliman University
College of Engineering and Design
PROPERTIES OF ALGORITHM
• Output:
• One always expects output/result (expected value/quantities) in terms
of output from an algorithm. The result may be obtained at different
stages of the algorithm. If some result is from the intermediate stage of
the operation then it is known as intermediate result and result
obtained at the end of algorithm is known as end result. The output is
expected value/quantities always have a specified relation to the inputs
• Effectiveness:
• Algorithms to be developed/written using basic operations. Actually
operations should be basic, so that even they can in principle be done
exactly and in a finite amount of time by a person, by using paper and
pencil only.
Silliman University
College of Engineering and Design
FLOWCHART
• The flowchart is a diagram which
visually presents the flow of data
through processing systems. This
means by seeing a flow chart one can
know the operations performed and
the sequence of these operations in a
system.
• Algorithms are nothing but sequence
of steps for solving problems. So a
flow chart can be used for
representing an algorithm. A
flowchart, will describe the operations VISIT THIS WEBSITE FOR
(and in what sequence) are required FLOWCHART TUTORIAL
to solve a given problem.
https://creately.com/blog/diagrams/flow
chart-guide-flowchart-tutorial/
Silliman University
College of Engineering and Design
Flowchart Symbols
Silliman University
College of Engineering and Design
General Rules of Flowchart
1. All boxes of the flowchart are connected with Arrows.
(Not lines)
2. Flowchart symbols have an entry point on the top of
the symbol with no other entry points. The exit point
for all flowchart symbols is on the bottom except for
the Decision symbol.
3. The Decision symbol has two exit points; these can be
on the sides or the bottom and one side.
4. Generally a flowchart will flow from top to bottom.
Silliman University
However, an upward flow can be shown as long as it
College of Engineering and Design
General Rules of Flowchart
5. Connectors are used to connect breaks in the
flowchart. Examples are:
• From one page to another page.
• From the bottom of the page to the top of the same page.
• An upward flow of more then 3 symbols
6. Subroutines and Interrupt programs have their own
and independent flowcharts.
7. All flow charts start with a Terminal or Predefined
Process (for interrupt programs or subroutines)
symbol.
Silliman University
College of Engineering and Design
Flowchart Examples
Problem 1: Find the area of a circle of radius r.
Silliman University
College of Engineering and Design
Flowchart Examples
Problem 2: Algorithm for find the greater number
between two numbers.
Silliman University
College of Engineering and Design
Flowchart Examples
Problem 3: Flowchart for the
calculate the average from 25
exam scores.
Silliman University
College of Engineering and Design
Advantages of Using Flowchart
1. Communication: A Flowchart can be used as a better
way of communication of the logic of a system and
steps involve in the solution, to all concerned
particularly to the client of system.
2. Effective analysis: A flowchart of a problem can be
used for effective analysis of the problem.
3. Documentation of Program/System: Program
flowcharts are a vital part of a good program
documentation. Program document is used for various
purposes like knowing the components in the
College of Engineeringprogram, complexity of the program etc.
Silliman University
and Design
Advantages of Using Flowchart
4. Efficient Program Maintenance: Once a program is
developed and becomes operational it needs time to
time maintenance. With help of flowchart
maintenance become easier.
5. Coding of the Program: Any design of solution of a
problem is finally converted into computer program.
Writing code referring the flowchart of the solution
become easy.
Silliman University
College of Engineering and Design
Activity # 3
• Try to answer the Following Questions
Silliman University
College of Engineering and Design
Activity # 3
• Try to answer the Following Questions