Analysis and Design of Algorithms: by Manju Choudhary
Analysis and Design of Algorithms: by Manju Choudhary
By
Manju Choudhary
1
Course Information
Textbook
Introduction to Algorithms 5nd ,Cormen,
Leiserson, Rivest and Stein, The MIT Press, 2001.
Others
Introduction to Design & Analysis Computer Algorithm 3rd, Sara
Baase, Allen Van Gelder, Adison-Wesley, 2000.
Fundamental of Computer Algorithms, Ellis Horowitz, Sartaj
Sahni, Sanguthevar Rajasekaran, 2010.
LMS: Advanced Algorithms by Manju
Enrollment key : csl502
2
Grading Policy
Total Marks: 200
Theory
65%----130 marks
Minor 1: 20 marks (Paper would be of 40 marks)
Minor 2: 20 marks (paper would be of 40 marks)
Internals : 25 marks (includes: online test, assignment, class test)
Major Exam: 65 marks (paper would be of 65 marks)
Practical
35%----- 70 marks
Lab Assessment will be through out the semester.
3
Objective of This Course
Major objective of this course is:
Basic Framework (RAM model)
To design and analyze algorithms
Design fast algorithms
Analysis of designed algorithms
Comparing Algorithms (i.e. their efficiencies)
Techniques for fast algorithms
Greedy , Dynamic, Backtracking, Branch & Bound
NP-Completeness Theory
Approximation theory
4
Approach:
Analytical.
5
Prerequisites:
Following background is necessity of this course:
Programming.
Data structures.
Discrete Mathematics
(Sets, Functions, Vectors, Matrix, Linear Inequalities, Linear
Equations)
6
WhaWhat is Algorithm?t is Algorithm?
A computer algorithm is a detailed set of instructions when
executed sequentially then solve a problem
Market
ITM
Market
Hospital
Playground
Gym
WhaWhat is Algorithm?t is Algorithm?
Market ITM
Hospital
Playground Gym
Algorithm:
1. Go straight.
2. Take left turn.
3. you will reach ITM.
WhaWhat is Algorithm?t is Algorithm?
1. Go straight
ITM
ITM
Market
Hospital
Playground
Gym
WhaWhat is Algorithm?t is Algorithm?
ITM
Market
Market
Hospital
Playground
Gym
aWhat is Algorithm?
2. Take Left turn
wrong
Market ITM
Market
Hospital
Playground
Gym
What is Algorithm?
2. Take left turn
WRONG
ITM
Market
Market
Hospital
Playground
Gym
WhaWhat is Algorithm?t is Algorithm?
2.Take left turn
ITM
Market
Market
Hospital
Playground
Gym
What is Algorithm??
A computer algorithm is a detailed set of instructions
when executed sequentially then solve a problem
WRONG
Algorithm:
1. Go straight.
2. Take 3 rd left turn. (no ambiguity)
3. you will reach ITM.
14
Characteristics of good Algorithm
Termination
15
Popular Algorithms, Factors of Dependence
16
Analysis and Design of Algorithm
17
Design of Algorithm
1. Devising the algorithm (i.e. method)
18
What is Algorithm Analysis
?
pp 19
Importance of Analyze
Algorithm
Need to recognize limitations of various algorithms
for solving a problem.
Need to understand relationship between problem
size and running time.
When is a running program not good enough?
Need to learn how to analyze an algorithm's runni
ng time without coding it.
Need to learn techniques for writing more efficient
code.
20
em?
Correctness
Does the input/output relation match algorithm r
equirement?
Amount of work done ( time complexity)
Basic operations to do task
Amount of space used ( space complexity)
Memory used
Simplicity, clarity
Verification and implementation.
Optimality
Is it impossible to do better?
21
Complexity
The complexity of an algorithm is simply the
amount of work the algorithm performs to co
mplete its task.
Time Complexity
# of operations as a function of input size.
Space Complexity
# of memory words needed by the algorithm.
24
Computational Model
Basic Idea:
It is a mathematical model of a computer.
25
Computational Model
27
Computational Model :RAM
28
Computational Model :RAM
30
Example: What is an Algorithm?
31
Example Algorithm A
Algorithm A
32
Example Algorithm B
This algorithm uses two temporary arrays.
2. While n > 1
For i 1 to n /2
t2[ i ] min (t1 [ 2*i ], t1[ 2*i + 1] );
copy array t2 to t1;
n n/2;
33 3. Output t2[1];
Visualize Algorithm B
34 6 5 9 20 8 11 7
Loop 1
6 5 8 7
Loop 2
5 7
Loop 3
5
34
Example Algorithm C
Sort the input in increasing order.
Return the first element of the sorted data.
34 6 5 9 20 8 11 7
Sorting
5 6 7 8 9 11 20 34
35
Example Algorithm D
For each element, test whether it is the minimum.
36
Which algorithm is better?
The algorithms are correct, but
which is the best?
Measure the running time (number
of operations needed).
Measure the amount of memory
used.
Note that the running time of the
algorithms increase as the size of the
input increases.
37
What do we need?
38
Time vs. Size of Input
Measurement
parameterized by the size
of the input. Td(n)
4
Tc (n)
The algorihtms A,B,C are
Running time
implemented and run in a
(second)
PC. 2 Tb (n)
Algorithms D is
Ta (n)
implemented and run in a
supercomputer.
0
Let Tk( n ) be the amount 500 1000
of time taken by the Input Size
39Algorithm