Professional Documents
Culture Documents
Lesson 6
Lesson 6
Lesson 6
Let’s now look at two simple algorithms to find the greatest among three numbers,
as follows:
ALGORITHM 1.
Step 1: Start
Step 2: Read the three numbers A, B, C
Step 3: Compare A and B. If A is greater perform step 4 else perform step 5.
Step 4: Compare A and C. If A is greater, output “A is greatest” else output “C is greatest”.
Perform step 6.
Step 5: Compare B and C. If B is greater, output “B is greatest” else output “C is greatest”.
Step 6: Stop
ALGORITHM 2.
Step 7: Start
Step 8: Read the three numbers A, B, C
Step 9: Compare A and B. If A is greater, store A in MAX, else store B in MAX.
Step 10: Compare MAX and C. If MAX is greater, output “MAX is greatest” else output “C is
greatest”.
Step 11: Stop
The algorithms both achieve the same goal, but in different ways. The programmer
selects the algorithm, based on each algorithm’s advantages and disadvantages. For
example, the first algorithm has more number of comparisons, whereas in the second
algorithm, an additional variable MAX is required.
FLOWCHART
Flowchart Symbols
A flowchart may be simple or complex. The most common symbols that are used to
draw a flowchart are—Process, Decision, Data, Terminator, Connector and Flow lines. While
drawing a flowchart, some rules need to be followed
We see that in a sequence, the steps are executed in linear order one after the other.
In a selection operation, the step to be executed next is based on a decision taken. If the
condition is true (yes) a different path is followed than if the condition evaluates to false
(no). In case of iterative operation, a condition is checked. Based upon the result of this
conditional check, true or false, different paths are followed. Either the next step in the
sequence is executed or the control goes back to one of the already executed steps to make a
loop.
Examples
• The first flowchart computes the product of any two numbers and gives the result.
The flowchart is a simple sequence of steps to be performed in a sequential order.
• The second flowchart compares three numbers and finds the maximum of the three
numbers. This flowchart uses selection. In this flowchart, decision is taken based
upon a condition, which decides the next path to be followed, i.e. If A is greater than
B then the true (Yes) path is followed else the false (No) path is followed. Another
decision is again made while comparing MAX with C.
• The third flowchart finds the sum of first 100 integers. Here, iteration (loop) is
performed so that some steps are executed repetitively until they fulfill some
condition to exit from the repetition. In the decision box, the value of I is compared
with 100. If it is false (No), a loop is created which breaks when the condition
becomes true (Yes).
Flowcharts have their own benefits; however, they have some limitations too. A
complex and long complex may run into multiple pages, which becomes difficult to
understand and follow. In addition, updating a flowchart with the changing
requirements is a challenging job.
Difference between Algorithm and Flowchart
If you compare a flowchart to a movie, then an algorithm is the story of that movie. In other
words the essence of a flowchart is an algorithm. In addition, there are many variations
between the algorithm and the flowchart in the field of computer programming about
different aspects, such as the precision, the way they show and how people feel about them.
Below is a table illustrating the differences between them in details.
Algorithm Flowchart
It is a procedure for solving problems. It is a graphic representation of a process.
The process is shown in step-by-step The process is shown in block-by-block
instruction. information diagram.
It is complex and difficult to understand. It is intuitive and easy to understand.
It is convenient to debug errors. It is hard to debug errors.
The solution is showcased in natural
The solution is showcased in pictorial format.
language.
It is somewhat easier to solve complex
It is hard to solve complex problem.
problem.
It costs more time to create an
It costs less time to create a flowchart.
algorithm.
Examples
Algorithm:
Flowchart
2. Determine whether a temperature is below or above the freezing point
Algorithm
Flowchart
Flowchart Examples - Medical Services
This is a hospital flowchart example that shows how clinical cases shall be processed. This
flowchart uses decision shapes intensively in representing alternative flows.
Flowchart Example – Simple Algorithm
A flowchart can also be used in visualizing algorithms, regardless of its complexity. Here is
an example that shows how flowchart can be used in showing a simple summation process.
References