Algorithms and Flowcharts
● Machines are mostly used to convert input into output.
● The process that makes this possible can be expressed as a set of
instructions.
Algorithms
● Algorithms: An algorithm is a finite sequence of step wise instructions to
perform a task.
● GR: Algorithms must be written in computer language for the computer to
execute it.
○ Computers cannot understand English or other languages.
● Computer program: An algorithm written in a computer language is called a
computer program.
● Computer programming: Act of writing an algorithm in a computer
language.
Writing an Algorithm
● An algorithm should have a finite number of steps.
● Each step should specify a definite action
● It should take input and produce output.
● Variables should be used when necessary
○ Variables are named containers that store values temporarily.
○ The assignment symbol or sign of equality (=) is used to store the
values.
● Each step should be referred to by a step number.
● Mathematical expressions should be used to perform calculations.
Characteristics of a good algorithm
● Input: An algorithm should be able to receive inputs
● Generality: An algorithm should be able to work on different sets of inputs
provided by the users.
● Finiteness: An algorithm should stop after execution of a finite number of
instructions.
● Output: An algorithm should produce the desired output.
● Definiteness: An algorithm should be precisely defined so that everyone takes
the same action.
● Uniqueness: The result of each step should be uniquely defined and should
depend on the input and results of previous steps.
Flowchart
● A Flowchart is a diagrammatic representation of an algorithm in which steps
are laid in a logical order using geometrical symbols.
(one page connectors are referred by numbers and offpage by letters)
Features of a flowchart
● A flowchart must have one start and stop button
● It’s direction of flow is generally top to bottom or left to right.
● Arrow lines should not cross each other.
● Arrowheads depict the flow of information or sequence of steps
Advantages of flowcharting
● Presentation: The logic of the solution can easily be communicated to
concerned people.
● Coding: Flowcharts can easily be translated into computer programs.
● De-bugging: Flowcharts make it easy to spot errors in the solution
● Evaluation: The steps of the solution can easily be tested
● Documentation: Flowcharts can be used to easily document a process.
Disadvantages of flowchart
● Hard to change
● Unsuitable for complex logic
● Unsuitable for all types of solutions. (Eg: Recursion)