Algorithms and Data Structures - Advanced sorting algorithms
Algorithms and Data Structures (WS15/16) Example Solutions ... · Algorithms and Data Structures...
11
Algorithms and Data Structures (WS15/16) Example Solutions for Unit 12-13 Question 2 In this problem, we will not distinguish the key x i and the node which store x i . Let X ij be an indicator random variable where X ij =1 iff x i is an ancestor of x j . Let S k be the size of subtree rooted at x k . We want to find E[S k ]. By definition, S k = ∑ n i=1 X ki . From class, we know E[X ki ] = Pr[X ki = 1] = Pr[x k has minimum priority among elements between x i and x k ]= 1 |k-i|+1 . Now we can compute E[S k ] directly. E[S k ] = E[ n X i=1 X ki ] = n X i=1 E[X ki ] = k X i=1 1 k - i +1 + n X i=k+1 1 i - k +1 from class = H k + H n-k - 1= O(log n) 1
Transcript of Algorithms and Data Structures (WS15/16) Example Solutions ... · Algorithms and Data Structures...
Algorithms and Data Structures (WS15/16)Example Solutions for Unit 12-13
Question 2
In this problem, we will not distinguish the key xi and the node which store xi.
Let Xij be an indicator random variable where Xij = 1 iff xi is an ancestor of xj . Let Sk bethe size of subtree rooted at xk. We want to find E[Sk].
By definition, Sk =∑n
i=1Xki . From class, we know E[Xki] = Pr[Xki = 1] = Pr[xk hasminimum priority among elements between xi and xk] =
1|k−i|+1 .
Now we can compute E[Sk] directly.
E[Sk] = E[
n∑i=1
Xki]
=
n∑i=1
E[Xki]
=k∑
i=1
1
k − i+ 1+
n∑i=k+1
1
i− k + 1from class
= Hk +Hn−k − 1 = O(log n)
1