Lecture# 7
Algorithm and flow chart
By: Dr. Shahzad Ashraf
Algorithms
A tool for solving a well-specified
computational problem
Input Algorithm Output
Algorithms must be:
Correct: For each input produce an appropriate output
Efficient: run as quickly as possible, and use as little
memory as possible – more about this later
3
.Algorithms Cont
A well-defined computational procedure that
takes some value, or set of values, as input and
produces some value, or set of values, as output.
Written in a pseudo code which can be
implemented in the language of programmer’s
choice.
4
Correct and incorrect algorithms
Algorithm is correct if, for every input instance, it ends
with the correct output. We say that a correct algorithm
solves the given computational problem.
An incorrect algorithm might not end at all on some input
instances, or it might end with an answer other than the
desired one.
We shall be concerned only with correct algorithms.
5
Problems and Algorithms
We need to solve a computational problem
“Convert a weight in pounds to Kg”
An algorithm specifies how to solve it, e.g.:
1. Read weight-in-pounds
2. Calculate weight-in-Kg = weight-in-pounds *
0.455
3. Print weight-in-Kg
A computer program is a computer-
executable description of an algorithm
6
The Problem-solving Process
Analysis
Problem
specification
Design
Algorithm
Implementation
Program
Compilation
Executable
(solution)
7
From Algorithms to Programs
Problem
Algorithm:
Algorithm A sequence
of instructions describing
how to do a task (or
process)
C Program
8
The End