k= log  /n=-logn/logα.α

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Name : Chu Hoàng Hải Long

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.

The minimum depth is attained if we pick children of proportionα, and the


maximum depth isobtained if we pick children of proportion 1-α. After k steps down
the tree in the first case,the size of the child sub-array is n×α k. If this sub-array is a
leaf in the recursion tree, then its size is 1 and we get the equation
1 =n×αk.

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.

3. Illustrate the operation of Radix-Sort on the following list of English words:


COW,DOG,SEA,RUG,ROW,MOW.BOX,TAB,BAR,EAR,TAR,DIG,BIG,TEA, NOW,FOX

COW SEA TAB BAR


DOG TEA BAR BIG
SEA MOB EAR BOX
RUG TAB TAR COW
ROW DOG SEA DIG
MOB RUG TEA DOG
BOX DIG DIG EAR
TAB => BIG => BIG => FOX
BAR BAR MOB MOB
EAR EAR DOG NOW
TAR TAR COW ROW
DIG COW ROW RUG
BIG ROW NOW SEA
TEA NOW BOX TAB
NOW BOX FOX TAR
FOX FOX RUG TEA

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)

b. T(n) = 2T (n/4) + n1/2. In this recurrence relation: a = 2, b = 4, d = 1/2.


a(2) = bd(2). Therefore T(n)  (n1/2 log n).

c. T(n) = 2T (n/4) + n. In this recurrence relation: a = 2, b = 4, d = 1.


a(2) < bd(4). Therefore T(n)  (n).

d. T(n) = 2T (n/4) + n^2. In this recurrence relation: a = 2, b = 4, d = 2.


a(2) < bd(16). Therefore T(n)  (n2).

You might also like