Download - Algorithms and Data Structures (WS15/16) Example Solutions ... · Algorithms and Data Structures (WS15/16) Example Solutions for Unit 12-13 Question 2 Inthisproblem,wewillnotdistinguishthekeyx

Transcript
Page 1: Algorithms and Data Structures (WS15/16) Example Solutions ... · Algorithms and Data Structures (WS15/16) Example Solutions for Unit 12-13 Question 2 Inthisproblem,wewillnotdistinguishthekeyx

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

Page 2: Algorithms and Data Structures (WS15/16) Example Solutions ... · Algorithms and Data Structures (WS15/16) Example Solutions for Unit 12-13 Question 2 Inthisproblem,wewillnotdistinguishthekeyx
Page 3: Algorithms and Data Structures (WS15/16) Example Solutions ... · Algorithms and Data Structures (WS15/16) Example Solutions for Unit 12-13 Question 2 Inthisproblem,wewillnotdistinguishthekeyx
Page 4: Algorithms and Data Structures (WS15/16) Example Solutions ... · Algorithms and Data Structures (WS15/16) Example Solutions for Unit 12-13 Question 2 Inthisproblem,wewillnotdistinguishthekeyx
Page 5: Algorithms and Data Structures (WS15/16) Example Solutions ... · Algorithms and Data Structures (WS15/16) Example Solutions for Unit 12-13 Question 2 Inthisproblem,wewillnotdistinguishthekeyx
Page 6: Algorithms and Data Structures (WS15/16) Example Solutions ... · Algorithms and Data Structures (WS15/16) Example Solutions for Unit 12-13 Question 2 Inthisproblem,wewillnotdistinguishthekeyx
Page 7: Algorithms and Data Structures (WS15/16) Example Solutions ... · Algorithms and Data Structures (WS15/16) Example Solutions for Unit 12-13 Question 2 Inthisproblem,wewillnotdistinguishthekeyx
Page 8: Algorithms and Data Structures (WS15/16) Example Solutions ... · Algorithms and Data Structures (WS15/16) Example Solutions for Unit 12-13 Question 2 Inthisproblem,wewillnotdistinguishthekeyx
Page 9: Algorithms and Data Structures (WS15/16) Example Solutions ... · Algorithms and Data Structures (WS15/16) Example Solutions for Unit 12-13 Question 2 Inthisproblem,wewillnotdistinguishthekeyx
Page 10: Algorithms and Data Structures (WS15/16) Example Solutions ... · Algorithms and Data Structures (WS15/16) Example Solutions for Unit 12-13 Question 2 Inthisproblem,wewillnotdistinguishthekeyx
Page 11: Algorithms and Data Structures (WS15/16) Example Solutions ... · Algorithms and Data Structures (WS15/16) Example Solutions for Unit 12-13 Question 2 Inthisproblem,wewillnotdistinguishthekeyx