Professional Documents
Culture Documents
Design
Lecture 1
Course webpage
http://web.uettaxila.edu.pk/uet/software/courses.htm
Office hours
Wed,Thrus 9:00-12:00 AM or make an appointment
Grading policy
Assign. 30%(10+20), Midterm: 30%, Final: 50%
Textbook
Introduction to Algorithms 2nd ,Cormen,
Leiserson, Rivest and Stein, The MIT Press, 2001.
o
Data Structures and Algorithm Analysis
Others
Introduction to Design & Analysis Computer Algorithm 3rd,
Sara Baase, Allen Van Gelder, Adison-Wesley, 2000.
Algorithms, Richard Johnsonbaugh, Marcus Schaefer, Prentice
Hall, 2004.
Introduction to The Design and Analysis of Algorithms 2nd
Edition, Anany Levitin, Adison-Wesley, 2007.
Friday, October 9, 2020
Analysis of Algorithm 4
Course Objectives
Analysis of Algorithm 6
Advanced Algo Analysis
COURSE
COURSEOUTLINE
OUTLINE
Analysis of Algorithm 7
Advanced Algo Analysis
COURSE
COURSEOUTLINE
OUTLINE
Analysis of Algorithm 8
What is Algorithm?
Algorithm
is any well-defined computational procedure that
takes some value, or set of values, as input and
produces some value, or set of values, as output.
is thus a sequence of computational steps that
transform the input into the output.
is a tool for solving a well - specified
computational problem.
Any special method of solving a certain kind of pr
oblem (Webster Dictionary)
Analysis of Algorithm 13
What is a program?
Analysis of Algorithm 21
HEURISTIC ALGORITHM
Correctness
Does the input/output relation match algorithm r
equirement?
Amount of work done (aka complexity)
Basic operations to do task finite amount of time
Amount of space used
Memory used
Important Features:
Finiteness.[algo should end in finite amount of
steps]
Definiteness.[each instruction should be clear]
Input.[valid input clearly specified ]
Output.[single/multiple valid output]
Effectiveness.[ steps are sufficiently simple and
basic]
AnalysisOctober
Friday, of Algorithm
9, 2020 27
performance analysis
English
American
A la russe
Analysis of Algorithm 30
Classic Multiplication
Running Time
80
with the input size.
60
Average case time is often
difficult to determine. 40
running time. 0
1000 2000 3000 4000
Easier to analyze Input Size
Crucial to applications such as
games, finance and robotics
Friday, October 9, 20 Analysis of Algorithm 36
20
Experimental Studies
Time (ms)
composition 5000
Use a method like 4000
System.currentTimeMillis() to 3000
get an accurate measure 2000
of the actual running time
1000
Plot the results
0
0 50 100
Input Size
Friday, October 9, 20 Analysis of Algorithm 37
20
Limitations of Experiments
Algorithm arrayMax(A, n)
currentMax A[0] 2
for (i =1; i<n; i++) 2n
(i=1 once, i<n n times, i++ (n-1) times:post
increment i.e 1+ n + n -1 = 2n )
if A[i] currentMax then 2(n 1)
currentMax A[i] 2(n 1)
return currentMax 1
Total 6n
46
Why asymptotic Notations
47
Input Size
48
Efficiency Measurement
49
Types of Analysis
52
Asymptotic Analysis
53
Asymptotic Notation
It's a measure of the longest amount of time it could possibly take for
integer n0 and a constant c > 0 such that for all integers n > n0, f(n) ≤
54
Asymptotic notations
O-notation
55
Asymptotic Notation
Big-Omega Notation Ω
This is almost the same definition as Big Oh, except that "f(n) ≥ cg(n)”
This makes g(n) a lower bound function, instead of an upper bound
function.
It describes the best that can happen for a given data size.
56
Asymptotic notations (cont.)
- notation
57
Asymptotic Notation
Theta Notation Θ
Theta Notation For non-negative functions, f(n) and g(n), f(n) is theta of
g(n) if and only if f(n) = O(g(n)) and f(n) = Ω(g(n)). This is denoted as
"f(n) = Θ(g(n))".
This is basically saying that the function, f(n) is bounded both from the
top and bottom by the same function, g(n).
58
Asymptotic notations (cont.)
-notation
59
Asymptotic notations (cont.)
Little-O Notation
For non-negative functions, f(n) and g(n), f(n) is little o of g(n) if and
only if f(n) = O(g(n)), but f(n) ≠ Θ(g(n)). This is denoted as "f(n) =
o(g(n))".
This represents a loose bounding version of Big O. g(n) bounds from
the top, but it does not bound the bottom.
60
Example
Associate a "cost" with each statement.
Find the "total cost“ by finding the total number of times
each statement is executed.
Algorithm 1 Algorithm 2
Cost Cost
arr[0] = 0; c1 for(i=0; i<N; i++) c2
arr[1] = 0; c1 arr[i] = 0; c1
arr[2] = 0; c1
... ...
arr[N-1] = 0; c1
----------- -------------
c1+c1+...+c1 = c1 x N (N+1) x c2 + N x c1 =
(c2 + c1) x N + c2
61
Another Example
Algorithm 3 Cost
sum = 0; c1
for(i=0; i<N; i++) c2
for(j=0; j<N; j++) c2
sum += arr[i][j]; c3
------------
c1 + c2 x (N+1) + c2 x N x (N+1) + c3 x N2
62
Rate of Growth