Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

Design and Analysis of

Algorithms

Lecture 01

Instructor Naveed ullah Safi 1


Introduction

Problem
A problem is an obstacle, difficulty,
challenge or a situation that needs to be
removed or solved
Problem Solving
It is a process of identifying a problem and
finding the best solution for it

Instructor Naveed ullah Safi 2


Program
A set of instruction that tells a computer what to
do is called program
Advantages of Computer Program
• Computer program can solve many problems by giving
instructions to the computer
• A computer program can be used to perform a task
repeatedly and quickly
• A program can process a large amount of data easily
• Different types of program are used in different fields to
perform certain task
3
Instructor Naveed ullah Safi
What is Algorithm?
 An algorithm is a step-by-step process to
solve a particular problem
 Also we can say that the step wise solution
of a problem is called algorithm
 The process of solving a problem becomes
simpler and easier with help of an algorithm
 It is easier to write an algorithm before
writing the actual computer program
Instructor Naveed ullah Safi 4
Properties of Algorithm

 The given problem should be broken


down into simple and meaningful steps
 The steps should be numbered
sequentially
 The steps should be descriptive and
written in simple English

Instructor Naveed ullah Safi 5


Pseudo language
 In Pseudo language we will write algorithm for the
solution of different problems.
 Pseudo language code is much like English
language which is simple, clear and easy to be
implemented in any programming language.
 Pseudo language code can’t be directly
implemented in programming language but a little
change is required for implementation.
 It is syntax free language and it does not follow the
grammatical rules of any programming language.

 Pseudo means not genuine but having the appearance of


Instructor Naveed ullah Safi 6
Pseudo language conventions(Formula)
 Indentation indicates block structure.
 The looping structure are while, for, repeat, until
have the same interpretation as in C++.
 The conditional structures are if, if-else and if-then
have the same interpretation as in C++.
 The arrow(<-) is used for assignment operator,
although you can also use = for that purpose.
 All the variables will be local and for global we
must state that clearly.
 Array elements are accessed by specifying the
array name followed by the index in square
brackets have the same interpretation as in C++.
Instructor Naveed ullah Safi 7
Algorithm example for average
algorithm : Average
This algorithm is used to calculate the average of four integer
numbers. Let avg is the float variable where the average stores.

Step-1: [Read data]


Read(a,b,c,d)

Step-2: [calculate average]


avg<- (a+b+c+d)/4

Step-3: [display the result]


display(avg)

Step-4: [finish]
exit
Instructor Naveed ullah Safi 8
Assignment
 Write down the algorithm to show that the
number entered through keyboard is even or
odd.
 Write down the algorithm for the multiplication
of two integer values.

Instructor Naveed ullah Safi 9

You might also like