ALGORITHM-AND-FLOW-CHART_copy
ALGORITHM-AND-FLOW-CHART_copy
1.1 Introduction
1.2 Problem Solving
1.3 Algorithm
1.3.1 Examples of Algorithm
1.3.2 Properties of an Algorithm
1.4 Flowchart
1.4.1 Flowchart Symbols
1.4.2 Some Flowchart Examples
1.4.3 Advantages of Flowcharts
1.1 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. One person goes
Bank to withdraw money. After knowing the balance in his account, he/she decides to with
draw the entire amount from his account but he/she has to leave minimum
balance in his account. Here deciding about how much amount he/she may with draw from the
account is one of the examples of the basic intelligence. During the process of solving any
problem, one tries to find the necessary steps to be taken in a sequence. In this Unit you will
develop your understanding about problem solving and approaches.
Can you think of a day in your life which goes without problem solving? Answer to this question
is of course, No. In our life we are bound to solve problems. In our day to day activity such as
purchasing something from a general store and making payments, depositing fee in school, or
withdrawing money from bank account. All these activities involve some kind of problem
solving. It can be said that whatever activity a human being or machine do for achieving a
specified objective comes under problem solving. To make it clearer, let us see some other
examples.
Example1: If you are watching a news channel on your TV and you want to change it to a
sports channel, you need to do something i.e. move to that channel by pressing that channel
number on your remote. This is a kind of problem solving.
Example 2: One Monday morning, a student is ready to go to school but yet he/she has not
picked up those books and copies which are required as per timetable. So here picking up
books and copies as per timetable is a kind of problem solving.
Example 3: If someone asks to you, what is time now? So, seeing time in your watch and telling
him is also a kind of problem solving.
Example 4: Some students in a class plan to go on picnic and decide to share the expenses
among them. So, calculating total expenses and the amount an individual has to give for picnic
is also a kind of problem solving.
Now, broadly we can say that problem is a kind of barrier to achieve something and problem
solving is a process to get that barrier removed by performing some sequence of activities
Here it is necessary to mention that all the problems in the world cannot be solved. There are
some problems which have no solution and these problems are called Open Problems.
If you can solve a given problem then you can also write an algorithm for it. In next section we
will learn what is an algorithm.
1.3 ALGORITHM
Algorithm can be defined as: “A sequence of activities to be processed for getting desired
output from a given input.”
Webopedia defines an algorithm as: “A formula or set of steps for solving a particular problem.
To be an algorithm, a set of rules must be unambiguous and have a clear stopping point”.
There may be more than one way to solve a problem, so there may be more than one
algorithm for a problem.
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:
Before writing an algorithm for a problem, one should find out what is/are the inputs to the
algorithm and what is/are expected output after running the algorithm. Now let us take some
exercises to develop an algorithm for some simple problems: While writing algorithms we will
use following symbol for different operations:
Algorithm:
Step1: Read\input the Radius r of the Circle
Step2: Area PI*r*r // calculation of area
Step3: Print Area
Problem2: Write an algorithm to read two numbers and find their sum.
Algorithm:
Step1: Start
Step2: Read\input the first num1.
Step3: Read\input the second num2.
Step4: Sum num1+num2 // calculation of sum
Step5: Print Sum
Step6: End
Algorithm:
Step1: Start
Step 2: Read Temperature in Fahrenheit F
Step 3: C = 5/9*(F-32)
Step 4: Print Temperature in Celsius: C
Step5: End
Type of Algorithms
These three control structures are sufficient for all purposes. The sequence is exemplified by
sequence of statements place one after the other – the one above or before another gets
executed first. In flowcharts, sequence of statements is usually contained in the rectangular
process box.
• The branch refers to a binary decision based on some condition. If the condition is true,
one of the two branches is explored; if the condition is false, the other alternative is taken.
This is usually represented by the ‘if-then’ construct in pseudo-codes and programs. In
flowcharts, this is represented by the diamond-shaped decision box. This structure is also
known as the selection structure.
Problem1: 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
Step6: End
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:
1. Start
2. Read n
3. I←1
4. Write I
5. I←I+2
6. If ( I <= n) then go to line 4
7. End
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:
1. Start
2. I ← 1000 and S ← 0
3. I ← I + 2
4. Write I
5. S ← S + I
6. If (I < 1998) then go to line 3
else go to line 7
7. Write S
8. End
Problem 4: Design an algorithm with a natural number, n, as its input which calculates the
following formula and writes the result in the standard output:
S = ½ + ¼ + … +1/n
1. Start
2. Read n
3. I ← 2 and S ← 0
4. S= S + 1/I
5. I ← I + 2
6. If (I <= n) then go to line 4 else write S in standard output
7. End
Combining the use of these control structures, for example, a loop within a loop (nested loops),
a branch within another branch (nested if), a branch within a loop, a loop within a branch, and
so forth, is not uncommon. Complex algorithms may have more complicated logic structure and
deep level of nesting, in which case it is best to demarcate parts of the algorithm as separate
smaller modules. Beginners must train themselves to be proficient in using and combining control
structures appropriately, and go through the trouble of tracing through the algorithm before they
convert it into code.
Donald Ervin Knuth has given a list of five properties for an algorithm, these properties are:
1) 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.
2) 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.
3) 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.
1.4 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 flowchart can be used for representing an algorithm. A flowchart, will describe the
operations (and in what sequence) are required to solve a given problem. You can see a flow
chart as a blueprint of a design you have made for solving a problem.
For example, suppose you are going for a picnic with your friends then you plan for the activities
you will do there. If you have a plan of activities then you know clearly when you will do what
activity. Similarly, when you have a problem to solve using computer or in other word you need
to write a computer program for a problem then it will be good to draw a flowchart prior to writing
a computer program. Flowchart is drawn according to defined rules.
1.4.1 Flowchart Symbols
There are 6 basic symbols commonly used in flowcharting of assembly language Programs:
Terminal, Process, input/output, Decision, Connector and Predefined Process. This is not a
complete list of all the possible flowcharting symbols, these are the ones used most often in the
structure of Assembly language programming.
Name Function
Process Indicates any type of internal operation inside the
Processor or Memory
There are a few things you can do to make your flowchart universally accepted. And there are
some things that you can do to make it visually pleasing to others as well.
If you’re planning to share your flowchart or hoping to use it on a presentation etc. then it’s
wise to use standard symbols. However, it is important to remember that the idea is to give out
information in an easy-to-understand manner. It is perfectly acceptable to use an alternative
image instead of the document symbol as long as the audience understands it.
Keeping the arrow flow to one side, using the same size symbols, naming the decision blocks,
processes, arrows, etc. are few things you can do to make it better.
Problem 4: Algorithm for find the greater number between two numbers.
Problem 5: Flowchart for the problem of printing even numbers between 9 and 100:
Problem 6: Flowchart for the problem of printing odd numbers less than a given number. It
should also calculate their sum and count.
Problem 7: Flowchart for the calculate the average from 25 exam scores.
Flow chart is used for representing algorithm in pictorial form. This pictorial representation of a
solution/system is having many advantages. These advantages are as follows:
2) Effective analysis: A flowchart of a problem can be used for effective analysis of the problem.
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.
1) What is an algorithm?
2) Explain need of an algorithm?
3) Write an algorithm to find average age of a group of 10 players?
4) Explain uses of Flowchart.
5) Draw a flowchart to find the largest of three numbers x, y and z.
References:
https://www.tutorialspoint.com/basics_of_computer_science/basics_of_computer_science_algor
ithm_flowchart.htm
https://www.visual-paradigm.com/tutorials/flowchart-tutorial/
https://warren2lynch.medium.com/a-comprehensive-guide-for-flowchart-over-50-examples-
785d6dfdc380
https://www.techbaz.org/Blog/Algorithm-and-Flowchart.php