DAA E-Content - Module 1 Introduction
DAA E-Content - Module 1 Introduction
Module-I: Introduction
Dr. A K Yadav
Associate Professor
August 1, 2025
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 1/87
Department of Computer Science and Engineering
Contents
Introduction to algorithms 3
Asymptotic notations 7
Relationship between notations 11
Recurrences 20
Recurrence Solution Methods 21
Substitution method 22
Iteration method 34
Recursion tree method 50
Master method (D&C) 58
Muster Theorem (S&C) 70
Complexity Analysis 80
Complexity analysis: Insertion sort 82
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 2/87
Department of Computer Science and Engineering
Introduction to algorithms
▶ What is an algorithm?
- An algorithm is a set of rules for carrying out calculation
either by hand or on a machine.
- An algorithm is a sequence of computational steps that
transform the input into output.
- An algorithm is a sequence of operations performed on data
that have to be organized in data structures.
- A finite set of instructions that specify a sequence of
operations to be carried out in order to solve a specific
problem or class of problems.
- An algorithm is an abstraction of a program to be executed
on a physical machine.
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 3/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 4/87
Department of Computer Science and Engineering
▶ Algoritm vs Program
- Algorithm is independent of programming language and
written in any natural language.
- Implementation of any algorithm in a programming language
is a program.
▶ Design Techniques
- Divide and Conquer (D&C)
- Dynamic Programming (DP)
- Greedy Approach
- Branch and Bound
- Backtracking
- Randomized
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 5/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 6/87
Department of Computer Science and Engineering
Asymptotic notations
1. O - notation ”Big O” : Asymptotic upper bound,
O(g(n)) = {f (n) : ∃c, n0 > 0 such that 0 ≤ f (n) ≤
cg(n) for all n ≥ n0 }
f (n) ∈ O(g(n))
f (n) = O(g(n))
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 7/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 8/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 9/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 10/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 11/87
Department of Computer Science and Engineering
d
X
▶ Let f (n) = ai ni where ad > 0, is a degree-d polynomial in
i=0
n and k is a constant then:
- if k ≥ d, then f (n) = O(nk ).
- if k ≤ d, then f (n) = Ω(nk ).
- if k = d, then f (n) = Θ(nk ).
- if k > d, then f (n) = o(nk ).
- if k < d, then f (n) = ω(nk ).
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 12/87
Department of Computer Science and Engineering
Examples
1. Show that an + b = O(n2 )
2. Show that 21 n2 − 3n = Θ(n2 )
3. Show that 12 n2 − 3n = Ω(n)
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 13/87
Department of Computer Science and Engineering
Solutions
1. Show that an + b = O(n2 )
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 14/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 15/87
Department of Computer Science and Engineering
1
c1 n2 ≤ n2 − 3n ≤ c2 n2
2
1 3
⇒ c1 ≤ − ≤ c2 after dividing n2
2 n
1 3
⇒ 0 < c1 ≤ −
2 n
1 3
⇒0< −
2 n
3 1
⇒ <
n 2
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 16/87
Department of Computer Science and Engineering
⇒n>6
Let n = 7
1
⇒ 0 < c1 ≤
14
1
Let c1 =
14
1 3
Now 0 < − ≤ c2
2 n
1
⇒ 0 < ≤ c2 when n = ∞
2
1
Let c2 =
2
1 2
⇒ 0 < 14 n ≤ 12 n2 − 3n ≤ 21 n2 for all n ≥ n0 = 7 and any
1
constant 0 < c1 ≤ 14 ≤ 12 ≤ c2 .
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 17/87
Department of Computer Science and Engineering
1
Let cn ≤ n2 − 3n
2
1
c ≤ n − 3 after dividing n both side
2
1
⇒c ≤ n+3
2
1
⇒ c ≤ n + 3n for all n > 0
2
7
⇒c≤ n
2
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 18/87
Department of Computer Science and Engineering
7 7
⇒ ≤ n for all n ≥ 1
2 2
7
∴c≤
2
7
Let c =
2
⇒ 72 n ≤ 12 n2 − 3n for all positive constants c ≤ 7
2 and for all
n ≥ n0 = 1.
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 19/87
Department of Computer Science and Engineering
Recurrences
A recurrence is an equation or inequality that describes a function
in terms of its value on smaller inputs.
(
nf (n − 1) if n > 1
f (n) =
1 if n = 1
(
2T (n/2) + Θ(n) if n > 1
T (n) =
Θ(1) if n = 1
(
T (n − 1) if n > 1
T (n) =
Θ(1) if n = 1
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 20/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 21/87
Department of Computer Science and Engineering
Substitution method
- In Substitution method there are two steps :
1 - First guess the solution
2 - Second use mathematical induction to find the constants and
show that the solution works.
- This method is powerful, but depends on the correctness of the
guess.
- Method can be used for either upper or lower bounds on a
recurrence.
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 22/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 23/87
Department of Computer Science and Engineering
⇒ T (n) = O(n lg n) then it must be the solution for the input size
n/2.
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 24/87
Department of Computer Science and Engineering
⇒ T (n) ≤ cn lg(n/2) + n
⇒ T (n) ≤ cn lg n − cn lg 2 + n
⇒ T (n) ≤ cn lg n − cn + n
⇒ T (n) ≤ cn lg n − n(c − 1)
⇒ T (n) ≤ cn lg n ∀c ≥ 1, n ≥ 2
∴ T (n) = O(n lg n)
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 25/87
Department of Computer Science and Engineering
√
T (n) = 2T ( n) + lg n (given) (4)
Take:
lg n = m (5)
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 26/87
Department of Computer Science and Engineering
⇒ n = 2m (6)
Put back the value of S(m) = T (2m ) and m from Eq. 5 into Eq. 9
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 27/87
Department of Computer Science and Engineering
⇒ T (n) = Ω(n lg n) then it must be the solution for the input size
n/2.
substitute the value of n as n/2 in Eq. 12.
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 28/87
Department of Computer Science and Engineering
⇒ T (n) ≥ cn lg(n/2) + n
⇒ T (n) ≥ cn lg n − cn lg 2 + n
⇒ T (n) ≥ cn lg n − cn + n
⇒ T (n) ≥ cn lg n + n(1 − c)
⇒ T (n) ≥ cn lg n ∀c ≤ 1, n ≥ 2
∴ T (n) = Ω(n lg n)
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 29/87
Department of Computer Science and Engineering
⇒ T (n) = O(lg n) then it must be the solution for the input size
n/2.
substitute the value of n as n/2 in Eq. 15.
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 30/87
Department of Computer Science and Engineering
T (n) ≤ c lg(n/2)) + 1
⇒ T (n) ≤ c lg(n/2) + 1
⇒ T (n) ≤ c lg n − c lg 2 + 1
⇒ T (n) ≤ c lg n − c + 1
⇒ T (n) ≤ c lg n − (c − 1)
⇒ T (n) ≤ c lg n ∀c ≥ 1, n ≥ 2
∴ T (n) = O(lg n)
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 31/87
Department of Computer Science and Engineering
T (n) = T (n − 1) + n (17)
⇒ T (n) = O(n2 ) then it must be the solution for the input size
n − 1.
substitute the value of n as n − 1 in Eq. 18.
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 32/87
Department of Computer Science and Engineering
⇒ T (n) ≤ c(n2 − 2n + 1) + n
⇒ T (n) ≤ cn2 − 2cn + c + n
⇒ T (n) ≤ cn2 − (2c − 1)n + c
Take value of c such that (2c − 1) ≥ c
⇒ T (n) ≤ cn2 ∀c ≥ 1, n ≥ 1
∴ T (n) = O(n2 )
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 33/87
Department of Computer Science and Engineering
Iteration method
- In iteration method, expend the right hand side of the recurrence
relation.
- Try to find out the series and number of terms in the series.
- Find out the sum of the series
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 34/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 35/87
Department of Computer Science and Engineering
Find the value of T (n/2) = 2T (n/4) + n/2 from Eq. 20 and put
into Eq. 20
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 36/87
Department of Computer Science and Engineering
Again find the value of T (n/4) = 2T (n/8) + n/4 from Eq. 20 and
put into Eq. 21
⇒ n/2i = 1
⇒ n = 2i
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 37/87
Department of Computer Science and Engineering
⇒ lg n = i
So after lg n iteration, the recurrence term will be terminated.
Eq. 23 will be
⇒ T (n) = nT (1) + n lg n
⇒ T (n) ≤ cn + n lg n, ∀c ≥ T (1)
⇒ T (n) ≤ cn lg n + n lg n, ∀n ≥ 2
⇒ T (n) = (c + 1)n lg n
⇒ T (n) ≤ c1 n lg n, ∀c1 ≥ (c + 1) > 0, ∀n ≥ 2
∴ T (n) = O(n lg n)
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 38/87
Department of Computer Science and Engineering
⇒ T (n) = 3 3T (n/16) + c(n/4)2 + cn2
3
T (n) = 9T (n/16) + 1 + cn2 (25)
16
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 39/87
Department of Computer Science and Engineering
2 !
3 3
T (n) = 27T (n/64) + 1 + + cn2 (26)
16 16
⇒ n/4i = 1
⇒ n = 4i
⇒ log4 n = i
So after log4 n iteration, the recurrence term will be terminated.
Eq. 27 will be
2 (log4 n−1) !
3 3 3
log4 n
⇒ T (n) = 3 T (1) + 1 + + + ··· + cn2
16 16 16
2 (log4 n−1) !
3 3 3
log4 3
⇒ T (n) = n T (1) + 1 + + + ··· + cn2
16 16 16
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 41/87
Department of Computer Science and Engineering
2 !
3 3
⇒ T (n) ≤ c1 n + 1 + + + ... cn2 , ∀c1 ≥ T (1)
16 16
1
⇒ T (n) ≤ c1 n + cn2
1 − 3/16
16
⇒ T (n) ≤ c1 n + cn2
13
16
2
⇒ T (n) ≤ c1 n + cn2 , ∀n ≥ 1
13
13c1 + 16c
⇒ T (n) ≤ n2
13
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 42/87
Department of Computer Science and Engineering
13c1 + 16c
⇒ T (n) ≤ c2 n2 where ∀c2 ≥ > 0 and ∀n ≥ 1
13
∴ T (n) = O(n2 )
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 43/87
Department of Computer Science and Engineering
T (n) = T (n − 1) + n4 (28)
⇒ T (n) = T (n − 2) + (n − 1)4 + n4
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 44/87
Department of Computer Science and Engineering
⇒n−i =0
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 45/87
Department of Computer Science and Engineering
⇒i =n
So after n iteration, the recurrence term will be terminated. Eq. 31
will be
⇒ T (n) = T (0) + 14 + 24 + 34 + · · · + (n − 1)4 + n4
⇒ T (n) ≤ T (0) + n4 + n4 + · · · + n4 , ∀n ≥ 1
⇒ T (n) ≤ (c + 1)n5
√
T (n) = T ( n) + n (32)
√ √ √
Find the value of T ( 2 n) = T ( 4 n) + 2 n from Eq. 32 and put into
Eq. 32
√ √
⇒ T (n) = T ( 4 n) + 2 n + n
√ √
T (n) = T ( 4 n) + 2 n + n (33)
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 47/87
Department of Computer Science and Engineering
√ √ √
Again find the value of T ( 4 n) = T ( 8 n) + 4 n from Eq. 32 and
put into Eq. 33
√ √ √
⇒ T (n) = T ( 8 n) + 4 n + 2 n + n
√ √ √
T (n) = T ( 8 n) + 4 n + 2 n + n (34)
√
2i
⇒ n=2
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 48/87
Department of Computer Science and Engineering
√
2i
⇒ lg( n) = lg 2
1
⇒ i lg n = 1
2
⇒ lg n = 2i
⇒ lg lg n = i
So after lg lg n iteration, the recurrence term will be terminated.
Eq. 35 will be
√ √ √
i−1
⇒ T (n) = n + 2 n + 4 n + · · · + 2 n + T (2)
⇒ T (n) ≤ n + n + n + . . . lg lg n times
⇒ T (n) ≤ n lg lg n
∴ T (n) = O(n lg lg n)
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 49/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 50/87
Department of Computer Science and Engineering
T ( n2 ) T ( n2 )
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 52/87
Department of Computer Science and Engineering
n n
2 2
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 53/87
Department of Computer Science and Engineering
n n
2 2
n n n n
22 22 22 22
.. .. .. .. .. .. .. ..
. . . . . . . .
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 54/87
Department of Computer Science and Engineering
n n
2 2
n n n n
22 22 22 22
.. .. .. .. .. .. .. ..
. . . . . . . .
T ( 2ni ) · · · · · · · · · · · · · · T ( 2ni )
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 55/87
Department of Computer Science and Engineering
T ( n4 ) T ( n4 ) T ( n4 )
cn2
n 2 n 2 n 2
c 4 c 4 c 4
n n n n n n n n
T ( 16 ) T ( 16 ) T ( 16 ) T ( 16 ) T ( 16 ) T ( 16 ) T ( 16 ) T ( 16 ) T(
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 56/87
Department of Computer Science and Engineering
n 2 n 2 n
c 4 c 4 c 4
n 2 n 2 n 2 n 2 n 2 n 2 n 2 n
c 16 c 16 c 16 c 16 c 16 c 16 c 16 c 16
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
. . . . . . . . . . . . . . . . . . . . . . .
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 57/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 59/87
Department of Computer Science and Engineering
T (n) = Θ nlog3 9 = Θ n2
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 60/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 61/87
Department of Computer Science and Engineering
T (n) = Θ (f (n)) = Θ (n lg n)
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 63/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 64/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 65/87
Department of Computer Science and Engineering
nlogb a = nlog2 2 = n1
T (n) = Θ n1 lg n = Θ (n lg n)
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 66/87
Department of Computer Science and Engineering
nlogb a = nlog2 8 = n3
T (n) = Θ n3
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 67/87
Department of Computer Science and Engineering
nlog2 4 = n2
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 68/87
Department of Computer Science and Engineering
4
⇒ dn3
8
1 3
⇒ dn ≤ cdn3
2
Where 21 ≤ c < 1, ⇒ c = 0.75
so dn3 = Ω(n2+ϵ ) for 0 < ϵ ≤ 1
Case 3 of Master Method will be applied and solution will be
T (n) = Θ n3
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 69/87
Department of Computer Science and Engineering
T (n) = aT (n − b) + f (n)
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 70/87
Department of Computer Science and Engineering
Proof:
Expend the left hand side term of given recurrence
T (n) = aT (n − b) + f (n)
n
n n
⇒ T (n) = a b T (0)+a b −1 f n− − 1 b +· · ·+af (n−b)+f (n)
b
n
b
−1
X n
⇒ T (n) = ai f (n − ib) + a b T (0)
i=0
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 71/87
Department of Computer Science and Engineering
n
Xb
⇒ T (n) ≤ ai f (n − ib)
i=0
n
b
X
⇒ T (n) = O nd ai
i=0
n
n
b
X 1 − a b +1
i 1
a = ≤ = O(1)
i=0
1−a 1−a
⇒ T (n) = O nd O(1)
⇒ T (n) = O nd
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 72/87
Department of Computer Science and Engineering
2. if a = 1 then
n n
b b
X
i
X n
a = 1= + 1 = O(n)
i=0 i=0
b
⇒ T (n) = O nd O(n)
⇒ T (n) = O nd+1
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 73/87
Department of Computer Science and Engineering
3. if a > 1 then
n
n
b
X a b +1 − 1 n
ai = = O(a b )
i=0
a−1
n
⇒ T (n) = O nd O(a b )
n
⇒ T (n) = O nd a b
so
d
O(n ) a<1
T (n) = O(nd+1 ) a=1
O(a bn nd )
a>1
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 74/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 75/87
Department of Computer Science and Engineering
T (n) = O (n)
2. Find the solution of T (n) = 78 T (n − 1) + n3
Here a = 87 , b = 1, f (n) = O(n3 ), d = 3,
Case 1 applies. So the solution is :
T (n) = O nd
T (n) = O n3
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 76/87
Department of Computer Science and Engineering
n
T (n) = O n1 2 2
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 78/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 79/87
Department of Computer Science and Engineering
Complexity analysis
Analyzing an algorithm means predicting the resources that the
algorithm requires. Resources may be memory, communication
bandwidth, computer hardware or CPU time. Our primary concern
is to measures the computational time required for the algorithm.
Running time:-The running time of an algorithm is the number of
primitive operations or steps executed on a particular input.
Why do we normally concentrate on finding only the worst-case
running time?
1. The worst-case running time of an algorithm gives us an
upper bound on the running time for any input. So it
guarantees that the algorithm will never slower than this.
2. In real applications, worst case normally occurs for example
searching a non existing data.
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 80/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 81/87
Department of Computer Science and Engineering
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 82/87
Department of Computer Science and Engineering
n
X n
X
T (n) = c1 n + c2 (n − 1) + c3 (n − 1) + c4 tj + c5 (tj − 1)
j=2 j=2
n
X
+c6 (tj − 1) + c7 (n − 1)
j=2
n
X n
X n
X
⇒ T (n) = an + b + c4 tj + c5 (tj − 1) + c6 (tj − 1)
j=2 j=2 j=2
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 83/87
Department of Computer Science and Engineering
T (n) = an + b = O(n)
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 84/87
Department of Computer Science and Engineering
2. Worst Case: The algorithm performs worst if key > A[i] for
each value of j and stops only when i < 1 in step 4.
Then it will execute always j times for each value of
j = 2, 3, . . . , n
so
n
X (n − 1)(2 + n)
j=
j=2
2
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 86/87
Department of Computer Science and Engineering
Thank you
Please send your feedback or any queries to ashok.cse@igu.ac.in
Module-I: Introduction Dr. A K Yadav Associate Professor Design and Analysis of Algorithm 87/87