Monday, January 7, 2019

Algorithm and Flowchart


Algorithm and Flowchart

Simple Definitions:

Algorithm: “A step by step procedure to solve any problem is called algorithm.”

Flowchart : “ A pictorial representation / form of algorithm is called Flowchart.”

Computer Program: The set of instruction written in a language which computer can understand is called computer program. Whenever you wish to write a computer programs then the main steps are as follows:

Algorithm : Creating an Algorithm
Flowchart : Drawing a flowchart based on Algorithm
Program : Converting a flowchart into a computer program.

Algorithm :

A step by step procedure to solve any problem is called algorithm.  An algorithm is a representation of a solution to a problem. The Algorithm is invented by Abu Ja’far Mohammed ibn Musa Al-Khawarizmi in the 9th century. The word is derived from the phonetic pronunciation of the last name of Mohammed ibn Musa Al-Khawarizmi, who was an Arabic mathematician who invented a set of rules for performing the four basic arithmetic operations on decimal numbers.
It is commonly used for data processing, calculation and other related computer and mathematical operations. An algorithm is also used to manipulate data in various ways, such as inserting a new data item, searching for a particular item or sorting an item.

To make a computer do anything, you have to write a computer program. (A computer program is a set of instruction given to the computer.) To write a computer program, you have to tell the computer, step by step, exactly what you want it to do. The computer then "executes" the program, following each step mechanically, to accomplish the end goal.
When you are telling the computer what to do, you also get to choose how it's going to do it. That's where computer algorithms come in. The algorithm is the basic technique used to get the job done. Let's follow an example to help get an understanding of the algorithm concept.

Example1:
Making Tea Algorithm:

Step 1:  Take a container or Vessel
Step 2: Put Ingredients such as Milk, sugar, tea etc.
Step 3:  Boil it
Step 4:  Serve the Tea

Making a cup of Tea by using kettle

Step 1:  Fill the kettle with water.
Step 2:  Switch on the power to heat the water.
Step 3:  Check for boiling water. If not, go back to Step 2.
Step 4:  Put all the ingredients to make tea.
Step 5:  Switch off the power.

Example2:

Let's say that you have a friend arriving at the airport, and your friend needs to get from the airport to your house. Here are four different algorithms that you might give your friend for getting to your home:

The taxi algorithm:

Step 1: Go to the taxi stand.
Step 2:  Get in a taxi.
Step 3 : Give the driver my address.

The call-me algorithm:

Step 1:  When your plane arrives, call on my cell phone.
Step 2:  Meet me outside baggage claim area.

The rent-a-car algorithm:

Step 1:  Take the shuttle to the rental car place.
Step 2:  Rent a car.
Step 3:  Follow the directions to get to my house.

The bus algorithm:

Step 1: Outside baggage claim, catch bus number 70.
Step 2:  Transfer to bus 14 on Main Street.
Step 3: Get off on Elm street.
Step 4:  Walk two blocks north to my house.

All four of these algorithms accomplish exactly the same goal, but each algorithm does it in completely different way. Each algorithm also has a different cost and a different travel time. Taking a taxi, for example, is probably the fastest way, but also the most expensive. Taking the bus is definitely less expensive, but a whole lot slower. You choose the algorithm based on the circumstances.

Flowcharts:

The pictorial or graphical representation or form of an algorithm is called Flowchart. Flowchart is invented by Frank Gilbreth in 1921.
A flowchart is a type of diagram that represents an algorithm, workflow or process. The flowchart shows the steps as boxes of various kinds, and their order by connecting the boxes with arrows. This diagrammatic representation illustrates a solution model to a given problem. Flowcharts are used in analyzing, designing, documenting or managing a process or program in various fields.
Flow charting is a tool developed in the computer industry, for showing the steps involved in a process. The first structured method for documenting process flow, the “flow process chart,” was introduced by Frank Gilbreth to members of American Society of Mechanical Engineers (ASME) in 1921 as the presentation “Process Charts—First Steps in Finding the One Best Way.”
There are various professional softwares are available on the web which are used to draw flowchart. 
Some popular software are:
1) Microsoft Word,
2) Smart Draw, 
3) Microsoft Visio,
4) Edraw Max, 
5) Google Drawings, 
6) Creately, 
7) yEd etc

Symbols used in Flow Chart:


Start / End:
The terminator symbol marks the starting or ending point of the system. it usually contains the word "Start" or "End"

Process:
A Box or Rectangle can represent a single step such as Sum = A + B

Input / Output:
It represent material or information entering or leaving the system, such as Read A, Read B

Decision:
A decision or branching point. Lines representing different decisions emerge from different points of the diamond.

Flow Line:
A Flow line indicate the sequence of the steps and the direction of flow.

Guidelines to draw a flowchart:

The flowchart should be neat, clean and easy to follow.
The usual direciton of the flow of a procedure or system (Arrow) is from left to right or top to bottom.
Only one flow line should come out from a process symbol.
For Example:
       
 
Only one flow line should enter a decision symbol.
Ensure that the flowchart has a logical start and finish.

Converting Algorithm to a Flowchart:

Flowchart based on a algorithm to find the sum of two numbers

Algorithm:

Step 1: Let A = 50    (here we are assigning the value 50 to A)
Step 2: Let B = 40   (here we are assigning the value 40 to B)
Step 3: Sum = A + B  ( Addition of the value of A and B and storing result in
Sum)
Step 4: Sum = 90   (Finally displaying result which is store in Sum i.e 90

Flowchart for sum of two numbers:

Decision Making:

The Decision making process is used whenever you have to choose one option from give two option. In other words we can say that you have to give answer in Yes or No whenever questioned asked to you.
Diamond  shaped symbol is used for decision making while drawing a flowchart.
Consider the following Algorithm and Flowchart for waking up in the morning. At Step 2 the question is asked and the answer is Yes or No. It is a decision making step where you have to decide whether to hit snooze or not. This decision taking step is represented as a diamond in the flowchart

Algorithm:

Step 1: The Alarm rings at a specified time.
Step 2: If you it Snooze, go back to Step1
Step 3:Else wake up
Step 4: Turn off Alarm

Flowchart:


Loops:

Repetition of a sequence of steps until a spefied condition is fulfilled or satisfied is called loop. In other words we can say that the loop means executing one statement multiple times as per the specified condition.
Consider a situation in which a sequence of steps has to be repeated. Look at the flowchart to understand the loops.

Algorithm:

Step 1: Get the Number 'N'
Step 2: Set variable Count be equal to 1
Step 3: Multiple = N X Count
Step 4: Display Multiple
Step 5: If Count is 10 go to End
Step 6: Add 1 to current value of Count and go to Step 3.
Step 7: End






The repetition of sequence starts with Count = 1. The value of N (i.e 12) is multiplied with 1 and output is printed. Since we want to repeat the multiplication till count become 10 so we will add 1 to the count. In the second iteration or repeatation the value of Count will become 2 and the value of N will be multiplied by 2 and output will be printed. A decision box is used to stop the repetition when the value of count becomes 11.

Question and Answers for Algorithm and Flowchart

Q1. Fill in the blanks.

a) The instructions written in a language which computer can understand is called Computer Program
b) A set of steps that are followed in order to solve any problem or to complete a task is called Algorithm
c) The graphical or pictorial form of an algorithm is called the Flowchart
d) A Flow line Symbol is used to connect one box of flowchart to another.
e) A decision box is diamond shape.

Q2. Match the elements of a flow chart and their purpose of use in the following situation

Q3. The following flowchart gives the steps followed while taking attendance in a class. Three Arrows and a loop are missing. Complete the flowchart as follows:

Draw three arrows and missing loop at the correct place
Label the decision arrow with Yes or No

Ans:





2 comments:

Highlights of Topics

Fun with Scratch 2.0 (Grade 4th) Q1. Match the following instructions with their blocks. Q2.Match the command with correct actio...