Asymptotic Analysis
Asymptotic Analysis
Asymptotic
Analysis
Matrix Tree
Prof. Sonu Gupta
Types of Data Structure
Interface
Add
Request to perform
operations Remove
Program Data
Find Structures
Result of operation
Display
Wall of ADT
operations
Wall of ADT operations isolates program from data structure
Prof. Sonu Gupta
Example of Abstract Data Type
step 1 − START
step 2 − declare three integers a, b & c step 1 − START ADD
step 3 − define values of a & b step 2 − get values of a & b
step 4 − add values of a & b step 3 − c ← a + b
step 5 − store output of step 4 to c step 4 − display c
step 6 − print c step 5 − STOP
step 7 − STOP
Algorithm 1 Algorithm 2
big = a if(a > b)
if(b > big) { if(a > c)
big = b return a
if (c > big) else
big = c return c
return big }
else
{ if(b > c)
return b
else
return c
} Prof. Sonu Gupta
Algorithmic Efficiency
Space Complexity
Time Complexity
algo sum()
{ s=0 --------- 1
for i= 1 to n --------- n + 1
s=s+a[i] ---------- n
return s ---------- 1
}
algo sum()
{ for i= 1 to n --------- n + 1
for j = 1 to n --------- n(n + 1)
cout<<i*j; ---------- n *n
}
5 ms worst-case
4 ms
3 ms
}
average-case?
best-case
2 ms
1 ms
A B C D E F G
Input
f(n) = 10n2+ 4n + 2
f(n) is O(n2) as
10n2+ 4n + 2 <= 11n2 for all n >=5
( c=11, n0= 5)