Analysis and Design of Algorithms
Analysis and Design of Algorithms
Analysis and Design of Algorithms
algorithms
1
Books
Fundamentals of Computer algorithms
Horowitz, Sahani and Rajasekaran
Introduction to Algorithms
Coremen, Leiserson
3
1. Input: zero or more quantities externally
supplied
2. Output: at least one quantity is produced
3. Definiteness: Each instruction must be
clear and unambiguous.
4. Finiteness: In all cases algorithm must
terminate after finite number
of steps.
5. Effectiveness: each instruction must be
sufficiently basic.
4
• Two algorithms on two systems
• Algorithm A1 50 n lg n
• Algorithm A2 2 n2
A2 Super computer
108 ins/sec
A1
P.C
106 ins /sec
5
For n = 106
6
Thus by using a fast algorithm , the personal
computer gives results
20 times faster than the result given by
super computer using a slow algorithm.
7
Complexity
Some questions to answer:
How fast can we solve a
problem?
There may be many algorithms for a
given problem. Which algorithm to use?
What are the classical algorithm
design techniques ?
Are there problems inherently difficult
to solve?
8
How do we express the complexity of algorithm?
9
Pseudocode
• Pseudocode is an English language like
representation of the code required for an algorithm.
11
• The typical selection statement is the two
way selection
• if (condition) action 1 else action 2.
• The part of the loop are identified by
indentation.
• Loop iterates a block of code. It closely
resembles the while loop. It is a pretest
loop.
12
Example
Algorithm deviation
It finds deviations from average.
Pre: nothing
Post: numbers are read and deviation
from average printed
13
1 i= 0
2 Loop(all data are read)
1 I=I+1
2 read numbers into array[i]
3 sum = sum + number
3 Average = sum / I
4 Print (average)
5 J=0
6 Loop (j < i)
1 j = j+ 1
2 dev = array[j] – average
3 print (array [ j] . Dev)
7 Return
8 End deviation
14
Asymptotic notations( O , Ω , Θ )
15