Analysis of Algorithms 02 _ Class Notes
Analysis of Algorithms 02 _ Class Notes
ENGINEERING
Algorithms
Analysis of Algorithms
about Course
Topic Intro
Topic
Intro
to Algo
why
what
of analysis
Topics to be Covered
Aprion Aposterion
Topic
IT 3
Adv disadu
About Aditya Jain sir
HI
1. Appeared for GATE during BTech and secured AIR 60 in GATE in very first attempt - City topper
2. Represented college as the first Google DSC Ambassador.
3. The only student from the batch to secure an internship at Amazon. (9+ CGPA)
4. Had offer from IIT Bombay and IISc Bangalore to join the Masters program
5. Joined IIT Bombay for my 2 year Masters program, specialization in Data Science
6. Published multiple research papers in well known conferences along with the team
7. Received the prestigious excellence in Research award from IIT Bombay for my Masters thesis
8. Completed my Masters with an overall GPA of 9.36/10
9. Joined Dream11 as a Data Scientist
10. Have mentored 12,000+ students & working professions in field of Data Science and Analytics
11. Have been mentoring & teaching GATE aspirants to secure a great rank in limited time
12. Have got around 27.5K followers on Linkedin where I share my insights and guide students and
professionals.
Telegram Link for Aditya Jain sir: https://t.me/AdityaSir_PW
TTTe
Topic : Analysis of Algorithms
How to Analyses?
Methodology of Analysis
Aposteriori Apriori
After implementation Before implementation
Topic : Analysis of Algorithms
2. Apriori Analysis
Carried out before the actual implementation of Algorithm.
Topic : Analysis of Algorithms
Advantages Disadvantages
1. Platform independent 1. It gives approximate value
2. Can be carried out without actual
I (Time complexity)
implementation
3. Helps us to compare the relative (Space complexity)
performance of 2 or more algorithms.
Topic : Analysis of Algorithms
Eg.1.
O
Maggie
A2
A1
O O
O
x2 > x x units x2 units
Asymptotic
Topic : Analysis of Algorithms
1
1
n
C 1
P anti
MT
update For
condita n 1 units
1
11 1
1
21 3
ⁿᵗ
5 4 i 3
stop
Topic : Analysis of Algorithms
1. Step-count method:-
Algo. AJSir(n) {
1. p =r q + r
2. x = y * z
O
→ 2units
→ 2units
o
3. for (i = 1, i <= n ; i++) { → (4n + 2) units
a=b+c
} optional
4. for (j = 1; j <= n, j++) {
for (k = 1; k < = n; k ++) { HE
x= y+z → (4n2 + 4n + 2) units
}
}
}
Topic : Analysis of Algorithms
Eg.2. for (i =1; i <=n; i++)→ (2n+2) Total operation = (2n + 2) + 2*n
{ = 4n + 2
a = b +c → (2*n) for (i =1; i <=4; i++)
} i=1→1 1→2
i <=4 → Four 2→2
8
Algo AJSir(n)
{ Total no. of operation
……… = 2 + 2 + (4n+2) + (4n2 + 4n + 2)
= 4n2 + 8n + 8 units of times
………
………
___
}
notify
Eft
step Fitood
Startup
2027 20 emp
yrs
5L
2030 100 emp
dominating
E
T
2040
mpp
2050 oemp interview
Topic : Analysis of Algorithms
→1
Constant
4 2 ARE
Linear → n
Quadratic → n2
Topic : Analysis of Algorithms
approach
1. Joffmagnituda
Step-count method:-
Algo. AJSir(n) {
1. p = q + r → 1 or 2 → constant →1
2. x = y * z → 1 or 2 → constant →1
3. for (i = 1, i <= n ; i++) { → n units
a=b+c n
nt2
}
4. for (j = 1; j <= n, j++) {
for (k = 1; k <= n; k ++) { Un 4n 2
x= y+z → n2 units
}
}
}
Topic : Analysis of Algorithms
Total units as per order of Magnitude approach
1 + n + n2
(n2 + n+ 1)
0
for same algorithm the number of units by step- count method → (4n2 + 8n + 8)
notation = O(n2)
Algo ATC
SameAlge
2
4 8 8 units
1
Step Count mtd
n tn
magnitude
2 Order of
8fzpqtg
rate of 0 m
growth k n
12asymptoticnotation
Topic : Analysis of Algorithms
Note.
Aim of apriori analysis is to get/represent the running time of on algo. As a
mathematical function of input size ‘n’.
ITAL
E.g.3.
T(n) = 2n2 + 2
Order of magnitude refers to the rate
ec
T(n) = 4n2 + 8n + 8
of growth of time w.r.t. ‘n’
T(n) = 5n2 + 2
Topic : Analysis of Algorithms
8.5
E
on
c
Topic : Analysis of Algorithms
7 128 49
(2n > n2 for larger values of n)
Topic : Analysis of Algorithms
values
(Poly vs Expo)
Inff Compass for larger
of
o
Topic : Analysis of Algorithms
Note:-
Gore
[Algorithm that takes polynomial unit of time all ore efficient that those with
exponential time.]
Topic : Analysis of Algorithms
as
Topic : Analysis of Algorithms
V
}
return I
If
} Print (“element not fund”)
0
Topic : Analysis of Algorithms
1. Best case → The input for which the algo. Runs min no. of times (does min
work.)
The time complexity for such input Best case TC
2. Worst case→ The input which of the algorithm run max no. of times
The time complexity for such input worst case TC
0
E
Examples:
1.
HI
B(n) < [A(n) = W(n)] Linear search, Binary search
2. [B(n) = A(n)] < W(n) Quick sort
3. [B(n) = A(n) = W(n)] Merge sort, Heap sort, Selection sort.
Summary
1 Apsion Analysis
Order of magnitude
count mtd
Step
Cases
27 Types
of Best case
27 Worst Case
THANK - YOU
32