











































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth analysis of running time calculations in algorithms, including factors affecting running time, consecutive statements, recursive functions, and recurrence relations. It also covers the maximum subsequence sum problem and its algorithms, logarithms in running time, and methods for computing running time.
Typology: Slides
1 / 83
This page cannot be seen from the preview
Don't miss anything!












































































7/7/2012 Algorithm Analysis 2-
EE 232 Data Structures Session-05 , Spring-
7/7/2012 Algorithm Analysis 2-
Chapter 2: Algorithm Analysis
7/7/2012 Algorithm Analysis 2-
Lets Recall
What is an Algorithm? a clearly specified set of simple instructions to be followed to solve a problem
What are Data structures? Methods of organizing data
Program = algorithms + data structures
7/7/2012 Algorithm Analysis 2-
Lets Recall…
Why should we analyse an algorithm?
Writing a working program is not good enough! The program may be inefficient If the program is run on a large data set, then the running time becomes an issue
7/7/2012 Algorithm Analysis 2-
We need a theoretical framework upon which we can compare algorithms
The idea is to establish a relative order among different algorithms, in terms of their relative rates of growth (of the running time)
The rates of growth are expressed as functions, which are generally in terms of the number of inputs n e.g. a running time function can be expressed as T( n )
7/7/2012 Algorithm Analysis 2-
Such functions describe the utilization of some precious resource (e.g. time or space) as the size of the problem increases
We can determine the exact running time of an algorithm, however for large inputs, the multiplicative constants and lower-order terms are dominated by the effects of the input size itself
7/7/2012 Algorithm Analysis 2-
*If we look at a slightly larger range from n = [0, 10], we begin to note that they are more similar:
*http://www.ece.uwaterloo.ca/~ece250/ docsity.com
7/7/2012 Algorithm Analysis 2-
*Extending the range to n = [0, 100], the similarity increases:
*http://www.ece.uwaterloo.ca/~ece250/ docsity.com
7/7/2012 Algorithm Analysis 2-
*They are different absolutely, for example, f(1000) = 1 000 000 g(1000) = 997 002 however, the relative difference is very small
and this difference goes to zero as n → ∞ The justification for the pair of polynomials being similar is that, both have the same leading term: n^2
*http://www.ece.uwaterloo.ca/~ece250/ docsity.com
7/7/2012 Algorithm Analysis 2-
We can throw away the lower-order terms and ignore the leading coefficients of the highest term as the problem size grows really, really large
7/7/2012 Algorithm Analysis 2-
Asymptotic Notation The “big-Oh” O - Notation f( n ) 1 = O (g( n )) , if there exists positive constants c and n 0 , such that f( n ) cg( n ) for all n ≥ n 0
f( n ) and g( n ) are functions over non-negative integers The growth rate of f( n ) is less than or equal to that of g( n )
f ( n)
c g n ( )
n (^0) Input Size
Running Time
1: means set membership i.e. f( n ) Є O (g( n ))
7/7/2012 Algorithm Analysis 2-
g( n ) is an upper bound on f( n ) O -notation provides an asymptotic upper bound on a function Used for worst-case analysis
Examples If f( n ) = 2 n^2 , then f( n ) = O ( n^4 ) , f( n ) = O ( n^3 ) and f( n ) = O ( n^2 ) are all technically correct but the last answer is the best
f( n)
c g n ( )
n 0 Input Size
Running Time
7/7/2012 Algorithm Analysis 2-
W–notation provides an asymptotic lower bound on a function Used to describe best- case running times
Examples n^3 grows faster than n^2 , so we can say that n^3 = W( n^2 )
Input Size
Running Time
f ( n) c g n ( )
n 0
7/7/2012 Algorithm Analysis 2-
The “big-Theta” Q-Notation
f( n ) = Q(g( n )) if there exists positive constants c 1 , c 2 , and n 0 , such that c 1 g( n ) f( n ) c 2 g( n ) for all n n 0
for all values of n to the right of n 0 , the values of f( n ) lies at or above c 1 g( n ) and at or below c 2 g( n )
Input Size
Running Time
f ( n)
n 0
c 2 g( n)
c 1 g( n)