algorithms and data structures (ws15/16) example solutions ... · algorithms and data structures...

Post on 08-Oct-2020

3 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

top related