Professional Documents
Culture Documents
k= log /n=-logn/logα.α
k= log /n=-logn/logα.α
k= log /n=-logn/logα.α
ID: 1596879
1. Suppose that the splits at every level of quicksort are in the proportion 1-s to s
where 0<s<1/2 is a constant. What is the minimum and maximum depth of a leaf in
the recursion tree.
From here
k= log /n=-logn/logα.α
The other case( Maximum depth) is symmetric. After k steps down the tree, the size
of the child sub-array is n×(1-α)k. If this sub-array is a leaf in the recursion tree,
then its size is 1 and we get the equation
1 =n×(1-α)k.
From here,
k= log1-/n=-logn/log(1-α)
2. Write pseudo code for the procedure MIN-Heapify(A,i) and analyse the worst
running time for this procedure
MIN-HEAPIFY(A, i)
l = LEFT(i)
r = RIGHT(i)
if l ≤ A.heap-size and A[l] < A[i]
smallest = l
else smallest = i
if r ≤ A.heap-size and A[r] < A[smallest]
smallest = r
if smallest != i
exchange A[i] with A[smallest]
MIN-HEAPIFY(A, smallest)
The time complexity of the above approach is O(n) and the auxiliary space used is
O(1) for both the above programs.
4. Use Masters’ theorem to give tight asymptotic bounds for the following
recurrences
Given the equation: T(n) = a T(n/b) + f(n), where f(n) (nd), Master theorem
states that:
T(n) (nd), if a < bd,
T(n) (nd log n), if a = bd,
T(n) (nlogba), if a > bd.
From the above therorem:
a. T(n) = 2T (n/4) + 1. In this recurence relation: a = 2, b = 4. and d = 0.
a(2) > bd (1). Therefore, T(n) (nlog42) = (n1/2)