0% found this document useful (0 votes)
8 views10 pages

Lecture 3

Uploaded by

himasree2507
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views10 pages

Lecture 3

Uploaded by

himasree2507
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Design and

Analysis of
Algorithm
Lecture 3: Recursion

Dr. Tauheed
Contents
Asymptotic
notation
Recursion

2
Properties of asymptotic notations
1. 2. 3.

Reflexivity: Satisfied by three asymptotic notation: Theta, Big-oh and Omega


Symmetry: Satisfied by three asymptotic notation: Theta notation

Transitivity: Satisfied by three asymptotic notation: All Five Notations

Transpose
if and only if
Symmetry:
Questions
(1) (2) (3) Let k and m are constants

Which of the following is Which of the following is (a)


true true (b)
(a) (a) (c)
(b) (b)
(c) (c) Which of the following is
not correct.

(a) (a) (c)


Analyzing Complexity
main()
{
a=b+c
How many times a main()
for (i=1;i≤n;i+1)
particular {{ main()
a=b+c;
x=y+z;{
statement is } for (i=1;i≤n;i+1)
a=b+c;
executed while for{ (i=1;i≤n;i+1)
}
running. { x=y+z;
}for (j=1;j≤n;j+1)
} {
p=q+r;
} } }
Analyzing Complexity

main() 8⇒1 16 ⇒ 1
{ 4⇒2 8⇒ 2
int n; 4⇒3
while(n>1) 2⇒3 2⇒ 4
{ 1⇒?? 1⇒??
n=n/2
}
} Complexity=
𝑚𝑎𝑖𝑛()
Problem 1 Problem 2 Problem 3
main()

𝑓𝑜𝑟 (𝑖=1;𝑖≤𝑛;)
{ {
for (i=1;i≤n;)

𝑓𝑜𝑟 (𝑗=1;𝑗≤𝑛;)
{ {
for(j=1;j≤i^2;)

𝑓𝑜r
{ {

(𝑘=1;𝑘≤133;)
for(k=1;k≤133;)
{

𝑥=𝑦+𝑎
{ x=y+a
}
} }
} }
} }
}
Analyzing Insertion Sort
Worst Case 𝑂 ( 𝑛2 )

Best Case O(n)

Average Case 𝑂 ( 𝑛2 )
Recursion
Definition
A function calling itself to solve a particular problem is called a
recursion

e.g.
Properties of recursion
•Recursive step
•Termination condition
•There should be change in its parametric value

e.g.

You might also like