You are on page 1of 4

A LGORITHMS & DATA S TRUCTURES

INF1 – 2003

Tutorial 3
Exercise 1
Let Ì ´Òµ, such that ½ , be the maximum of ̽ ´Òµ ½. Then the probabilities Ô satisfy Ô½ · Ô¾ · ¡ ¡ ¡ · Ô
Ì

´ µ and recall that
Ò Ì Ò Ï Ò

´µ
Ò

Ô

¡ ´µ
Ì Ò

Ô

¡ ´µ
Ì Ò

Ì

´µ
Ò

Ô

Ì

´µ
Ò

½

½

½

½

ÑÜ ´µ

´µ

Exercise 2
We shall solve the following recurrence equation

¾ · ´   ½µ for ½ by repeated substitutions. Let us unfold ´ µ. ´ µ ¾ · ´   ½µ ¾ · ¾ · ´   ¾µ ¾ · ¾ · ¾ · ´   ¿µ Observe the pattern ´ µ ¾ · ¾ · ¡ ¡ ¡ · ¾ · ´   µ for . So if  ½ then
Ì Ò Ì Ò Ò Ì Ò Ì Ò Ì Ò Ì Ò Ì Ò

Ì

´½µ ´µ

´ µ ¾ · ¾ · ¡ ¡ ¡ · ¾ · ´   · ½µ ¾´   ½µ · ´½µ ¾   ¾ ·
Ì Ò Ò Ò Ì Ò

Proof: by induction on n we show that Ì ´Òµ ¾Ò · . In the base case Ò ½ and Ì ´½µ ¾¡½· as required. Let Ò ½. By IH (induction hypothesis) assume Ò. Now that Ì ´ µ ¾ · for all ½
Ì Ò

´Ò ½µ

ßÞ   ¢

ßÞ ¢

Ì Ò

Ì Ò

Ì Ò

Ò

Ò

¾ ·
Ò

´µ

(by definition) ¾·Ì ´Ò ½µ

(by IH) ¾·¾´Ò ½µ·

¾·¾  ¾·
Ò

¾·
Ò

Exercise 3
We shall solve the following recurrence equation

´   ½µ for ½ by repeated substitutions. Let us unfold ´ µ. ´µ ´   ½µ ´   ½µ ´   ¾µ ´   ½µ´   ¾µ ´   ¿µ Observe the pattern ´ µ ´   ½µ´   ¾µ ¡ ¡ ¡ ´   · ½µ ´   µ for
Ì Ò ÒÌ Ò Ì Ò Ò Ì Ò ÒÌ Ò Ò Ò Ì Ò Ò Ò Ò Ò Ò Ì Ò Ì Ò Ò Ò Ì Ò Ò Ì Ò

Ì

´¼µ ´µ

½

Ò

. So if
Ò

then

´µ ´¼µ ´µ

Ò Ò

´  ½µ´  ¾µ ¡ ¡ ¡´   ·½µ ´¼µ
Ò Ò Ò Ì

Ì Ì

Proof: by induction on n we show that Ì Ò Ò Ò ½ ¼ as required. Let Ò ¼. By IH (induction hypothesis) assume that for all ¼ Ò. Now
Ì Ò

´  ½µ´  ¾µ ¡ ¡ ¡¾¡½ ¡ ¡ ¡ ´¼µ ´µ . In the base case ¼ and
Ò Ò Ò Ì

´µ

(by definition) ÒÌ ´Ò   ½µ 1

(by IH) Ò ¡ ´Ò   ½µ

Ò

Observe that ´Ò · ½µ ¾ solve the following recurrence equation ½ ½ · ´¾   µ for ¼. such that we consider only the points where Ò ¾ for some integer ´¾ · ½µ ¾ ¾  ½ . ¾ implies that ÐÓ ´ µ. then ¿Ò Ò ¾  ¾·½ ¾  ½ ¾ Ò Ò Ò b) Let us fix e. Ò¼ the second case can be proved by induction. Another possibility and Å ¾ because Ò · ¾Ò for all Ò . We want to show that Ò · ¾Ò. For the inductive step let Ò and by IH we that · ¾´Ò   ½µ. ´¾ µ ½ · ´¾   µ ½ · ½ · ´¾   µ ½ · ½ · ½ · ´¾   µ Observe the pattern ´¾ µ · ´¾   µ for .e. Let us reformulate the recurrence equation ¼. By IH (induction · ½ for all ¼ . by repeated substitutions. which assume that ´Ò   ½µ · is true because Ò · ´   ½µ · · ½ Ò (by IH) ¾´Ò   ½µ · ½ . So if then ´¾ µ · ´¾ µ · ½ However. · ½. Then Ï ´½µ ½ and Ï ´Òµ ½·Ï ´ ´Ò·½µ ¾ µ for Ò ½.g. Ò   ·½ and assume that .g. Now hypothesis) assume that ´¾ µ ´¾ µ (by definition) ½ · ´¾   µ (by IH) ½ · ´   ½µ · ½ · ½ Ï Ï ´¾ µ ´¾ µ ¼ ½ Ï ½ Ï Ï Ï Ï ¾ Ï ¿ Ï Ï Ï Ï ¼ Ò ¾ Ò Ï Ò ¾Ò Ï Ï ¼ Ï Ï Ï ½ Exercise 5 Ì Ò ´µ Ò ¿ Exercise 6 a) Let us fix Ò¼ ½ and Å . Hence we shall Let Ò ¾ . i. then Ò · Ò for all Ò ½. In the base case ¼ Proof: by induction on k we show that ´¾ µ and ´¾ µ (by definition) ½ ¼ · ½ as required. Ò¼ ½ and Å Why and how did we find it? ·¾ Ò Ò ¿ Å ¡ Ò for every Ò Ò¼ .A LGORITHMS & DATA S TRUCTURES INF1 – 2003 Exercise 4 Let Ò be the size of the array. So ´ µ ÐÓ · ½. The validity of is e. ¿ ·¾ Ò ¿ ¿ ·¾ Ò Ò 2 . In the basic step we have to check ¾ ¡ which is true.. Let us unfold ´¾ µ. Let ¼.

To prove Ô Ò ´Ò   ½µ ¡ ¾ is the same as to prove Ò Ô´Ò   ½µ ¡ ¾ (both sides are non-negative). We aim to show that (1) In order to do that we will in fact prove a stronger claim ´   ½µ ¡ ¾ If we succeed to show this then by IH ´   ½µ ¡ ¾ Ò (2) To finish the proof we will now argue that (2) is true for all Ò ½¼¼. and the ¾ and ¾ Ò Å ½ ¾. which is the same Ô¾ ¾ Ô¾ ½ . Next we have to show that Ò¾ ·¾Ò · is ª´Ò¾ µ. For the base case (n=100) we have ½¼¼ calculator if you want to :-)). Ò¼ Ò ¾. ¾¼Ò¾ Ç ´Ò µ. which is obviously true for all Ò ½¼¼ because Ô¾ ½ ³ ½½. as Ò d) Let us fix. e.g. which is the same as ¾ Ò ¡ ´ ¾   ½µ. then ¡ ÐÓ Ò ¾ Ò Ò ¾ ´½ ¾µ ¡ ¾ Ò Ò ¾ for all e) First we show that Ò for all Ò ½. which is the same as Ò ´Ò   ½µ ¡ ¾. Let ·¾ · ·¾ · Ò Ò Ç Ò Ò ¾ Ò¼ Ò ¾ ¾ Ò ¾ ½ and ½½.A LGORITHMS & DATA S TRUCTURES INF1 – 2003 c) Let Ò¼ ½¼¼ and Å ½. Let Ò¼ ½ and Å ¾ Ò for all Ò ½. Let Ò ¾ ½¼¼ which is true (check this on a ½¼¼ and we assume by IH that ´   ½µ ¾ Ò Ò Ò Ò Ò ¾ Ò  ½. these are not optimal estimates) Ò ¾ Ç Ò ´ µ ¾ ¾¼ Ò ¾ Ç Ò ´ µ and ¾¼ Ò ¾ Ç ´¾ µ even if Ò (and we usually write only Ç´ÐÓ Òµ since the base of the logarithm is irrelevant for the Ç-notation as proved during the lecture) ÐÓ ¿· The argument for this is the following: ÐÓ ´¿Ò µ ÐÓ ¿·ÐÓ Ò ½¼ · ¾ · ½¼¼¼ · ÐÓ ´¿ µ Ò ¿ Ò Ç Ò Ç Ò Ò ½ ½ ¾ Ò Ò Ò Ç ´ µ ´¾ µ ´ µ ´ÐÓ µ ¿ Ò Ç Ò ¾ ¾Ò ¡ ÐÓ Ò Ç ´ÐÓ Ò µ Ç ´ÐÓ ¾Ò µ 3 . Ô ¾ Ò  ½ ¡ ¾ ¾ Ò . Then ½½ ¡ Å Ò ¾ Å ¾ ½ which Exercise 7 ¯ ¾¼ ¯ ¯ ¯ ¯ ¿ (!!! but also e. immediately implies that Ò¾ · ¾Ò · · ¾ · is ´ µ. which is the same as Ô Ô Ô Ô Ò Ò ¡ Ô¾   ¾. ¾ inequality (1) is also proven.g. The argument for “why” is a little bit more difficult this time and we will prove it by induction on Ò. Then Ò ¾Ò for all Ò ½¼¼.

A LGORITHMS & DATA S TRUCTURES INF1 – 2003 Exercise 8 It is true that ¾Ò is Ç´¿Ò µ but ¾Ò is not ª´¿Ò µ. Hence ¾Ò is not ¢´¿Ò µ. Exercise 9 Assume that ´Òµ Ç´ ´Òµµ and ´Òµ Ç´ ´Òµµ which means that there are natural numbers Ò¼ and Ò½ . and real numbers ż and Ž such that ¡ ´ µ for all and ¡ ´ µ for all . which implies that ¡ Ž µ¡ ´ µ Ò Å¾ ¡ ´µ Ò 4 . ÑÜ and ¡ Let us define ´µ ¡ ´µ ¡ ´ ¡ ´ µµ ´ for all and hence ´ µ ´ ´ µµ. Ò Å¼ Ò Ò Ò¼ Ò Å½ Ò Ò Ò½ Ò¾ Ò¼ Ò½ ż ž ż Ò Å¼ Ò Å½ Ò Ò Ò¾ Ò Ç Ò ¯ ´µ ¯ ´µ Ž ż .