











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lecture is part of lecture series for Design and Analysis of Algorithms course. This course was taught by Dr. Bhaskar Sanyal at Maulana Azad National Institute of Technology. It includes: Merge, Algorithm, Analysis, Elements, Running, Time, Sort, Recursive, Linear, Telescoping, Sum, Relation, Substitution
Typology: Slides
1 / 19
This page cannot be seen from the preview
Don't miss anything!












T(n) / n + T(n/2) / n/2 + T(n/4) / n/4 + ….+ T(2) / 2 = T(n/2) / 2 + 1 + T(n/4) / n/4 + 1 + T(n/8) / n/8 + 1 +…..+ T(1) / 1 + 1
T(n) = 2 T(n/2) + n
7
8
10
The pivot is the smallest (or the largest) element
T(N) = T(N-1) + cN, N > 1
Telescoping:
T(N-1) = T(N-2) + c(N-1)
T(N-2) = T(N-3) + c(N-2)
T(N-3) = T(N-4) + c(N-3) …………... T(2) = T(1) + c.
11
c(N) + c(N-1) + c(N-2) + … + c.
c times (the sum of 2 thru N)
= T(1) + c (N (N+1) / 2 -1) = O(N^2 )
13
Telescoping:
T(N) / N = T(N/2) / (N/2) + c
T(N/2) / (N/2) = T(N/4) / (N/4) + c
T(N/4) / (N/4) = T(N/8) / (N/8) + c
……
T(2) / 2 = T(1) / (1) + c
14
Add all equations:
T(N) / N + T(N/2) / (N/2) + T(N/4) / (N/4)
= (N/2) / (N/2) + T(N/4) / (N/4) + … + T(1) / (1) + c.logN
After crossing the equal terms:
T(N)/N = T(1) + cLogN T(N) = N + Nc*LogN = O(NlogN)
16
17
Some fixed element: e.g. the first, the last, the one in the middle.
Bad choice - may turn to be the smallest or the largest element, then one of the partitions will be empty
Randomly chosen (by random generator)
19
The median-of-three choice:
take the first, the last and the middle element.
Choose the median of these three elements.