BCS202L- Data Structures and
Algorithms
Dr. Iyappan Perumal
Assistant Professor Senior Grade 2
School of Computer Science & Engineering
VIT, Vellore.
BCS202L- Data Structures and
Algorithms
Text Books:
1. Mark A. Weiss, Data Structures & Algorithm Analysis in C++, 4 th
Edition, 2013,Pearson Education.
Reference Books:
1. Alfred V. Aho, Jeffrey D. Ullman and John E. Hopcroft, Data
Structures and Algorithms,1983, Pearson Education.
2. Horowitz, Sahni and S. Anderson-Freed, Fundamentals of Data
Structures in C, 2008, 2nd Edition, Universities Press.
3. Thomas H. Cormen, C.E. Leiserson, R L. Rivest and C. Stein,
Introduction to Algorithms, 2009, 3rd Edition, MIT Press.
Module 1: Algorithm Analysis(8 Hours)
Importance of algorithms and data structures
Fundamentals of Algorithm Analysis( Space and Time
Complexity)
Asymptotic notations and orders of growth.
Efficiency of Algorithm
Analysis of non-recursive and recursive algorithms
Asymptotic analysis for recurrence relation:
◦ Iteration Method
◦ Substitution Method
◦ Master Method
◦ Recursive Tree Method
Types of Analysis
Worst case
◦ Provides an upper bound on running time
◦ An absolute guarantee that the algorithm would not run
longer, no matter what the inputs are
Best case
◦ Provides a lower bound on running time
◦ Input is the one for which the algorithm runs the fastest
Lower Bound Running Time Upper Bound
Average case
◦ Provides a prediction about the running time
◦ Assumes that the input is random
Orders of growth
1<logn<√n<n<nlogn<n2<n3<……2n < 3n<nn
Asymptotic Notations and orders of
growth
Running time of an algorithm as a function of
input size n for large n.
Describes the behavior of the time or space
complexity for large instance characteristics.
Describes behavior of function in the limit.
Written using Asymptotic Notation.
◦ Big Oh (O)
◦ Big Omega (Ω)
◦ Theta (Q)
◦ Little Oh (O)
◦ Little Omega (w)
Big Oh (O) NOTATION
Big Oh (O) notation provides an upper
bound for the function f(n).
Max amount required for execution is
calculated(i.e .,Worst Case)
Definition: Let f(n), g(n) be two non-
negative functions, Then f(n) = O(g(n)) if
there exists 2 Positive Constants C, n0
such that f(n) c *g(n), n n0
Graphical Representation of
Big Oh (O) Notation
t
Big Oh (O) Notation - Example
Let take f(n) = 3n+2, g(n)=n
To Prove: f(n) = O(g(n))
Next, What is the Condition here??
f(n) c *g(n), n n0
3n+2 c*n
Note: we need to ensure some “c” value here
Let us assume that c=4
if n0=1, 5 4 ---> False
if n0=2, 8 8 ---> True
if n0=3, 11 12 ---> True
Conclusion: n0 Value should be greater than 2. So
the condition is satisfied when n 2
Big Omega (Ω) NOTATION
Big Omega (Ω) notation provides an
lower bound for the function f(n).
Min amount required for execution is
calculated(i.e .,Best Case)
Definition: Let f(n), g(n) be two non-
negative functions, Then f(n) = Ω(g(n)) if
there exists 2 Positive Constants C, n0
such that f(n) c *g(n), n n0
Graphical Representation of
Big Omega (Ω) Notation
t
Big Omega(Ω) Notation - Example
Let take f(n) = 3n+2, g(n)=n
To Prove: f(n) =Ω(g(n))
Next, What is the Condition here??
f(n) c *g(n), n n0
3n+2 c*n
Note: we need to ensure some “c” value here
Let us assume that c=1
if n0=1, 5 1 ---> True
if n0=2, 8 2 ---> True
if n0=3, 11 3 ---> True
Conclusion: n0 Value should be greater than 1. So
all the condition is satisfied when n 1
Theta (Q) NOTATION
Theta (Q) notation used when an algorithm
can be bounded both from above and below
by the same function.
Average amount of run time required for
execution.(i.e .,Average Case)
Definition: Let f(n), g(n) be two non-
negative functions, Then f(n) = Ω(g(n)) if
there exists 3 Positive Constants C1, C2,n0
such that C1*g(n) f(n) C2 *g(n), n > n0
Graphical Representation of
Theta (Q) Notation
t
Theta (Q) Notation - Example
Let take f(n) = 3n+2, g(n)=n
To Prove: f(n) = Q(g(n))
Next, What is the Condition here??
C1*g(n) f(n) C2 *g(n), n n0
C1*n 3n+2 C2*n
Note: we need to consider some “C1=1 and C2 =4” value here
if n0=1, 1*1 3(1)+2 4*1 => 1 5 4 - False
if n0=2, 2 8 8 ---> True
if n0=3, 3 11 12 ---> True
Conclusion: n0 Value should be greater than 2. So
the condition is satisfied when n > 1
Relations Between Q, W, O
Theorem : For any two functions g(n) and f(n),
f(n) = Q(g(n)) iff
f(n) = O(g(n)) and f(n) = W(g(n)).
I.e., Q(g(n)) = O(g(n)) W(g(n))
In practice, asymptotically tight bounds are
obtained from asymptotic upper and lower
bounds.
Little Oh (O) NOTATION
Definition: Let f(n), g(n) be two non- negative functions,
Then f(n) = O(g(n)) such that lim [f(n) / g(n)] = 0
n
Little Omega (w) NOTATION
Definition: Let f(n), g(n) be two non- negative functions,
Then f(n) = O(g(n)) such that lim [f(n) / g(n)] =
n
Thank You