Top Banner
October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charle s E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary search trees •Expected node depth •Analyzing eight • Convexity lemma • Jensen’s inequality • Exponential Prof. Erik Demaine
37

October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

Mar 27, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson L21

Introduction to Algorithms6046J18401J

LECTURE9Randomly built binary search treesbullExpected node depthbullAnalyzing eight1048707 bull Convexity lemma1048707 bull Jensenrsquos inequality1048707 bull Exponential heightbullPost mortem

Prof Erik Demaine

L22October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Binary-search-tree sortTlarr empty ⊳Create an empty BSTfor i= 1 to n do TREE-INSERT (T A[i])Perform an inorder tree walk of T

ExampleA= [3 1 8 2 6 7 5]

Tree-walk time = O(n) but how long does it take to build the BST

L23October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST sortBST sort performs the same comparisons as quicksort but in a different order

The expected time to build the tree is asymptot-icallythe same as the running time of quicksort

L24October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Node depthThe depth of a node=the number of comparisons made during TREE-INSERT Assuming all input permutations are equally likely we have

Average node depth

(quicksort analysis)

(comparison to insert node i )

L25October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Expected tree heightBut average node depth of a randomly built BST = O(lg n)does not necessarily mean that its expected height is also O(lg n)(although it is)

Example

L26October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Height of a randomly built binary search tree

Outline of the analysisbull Prove Jensenrsquos inequality which says that f(E

[X]) leE[f(X)] for any convex function fand random variable X

bull Analyze the exponential height of a randomly built BST on n nodes which is the random variable Yn= 2Xn where Xn is the random variable denoting the height of the BST

bull Prove that 2E[Xn]leE[2Xn ] = E[Yn] = O(n3) and hence that E[Xn] = O(lg n)

L27October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convex functionsA function f RrarrR is convex if for all αβge0 such that α+ β= 1 we have

f(αx+ βy) leα f(x) + β f(y)

for all xyisinR

L28October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma

Lemma Let f R rarrR be a convex function and let α1 α2 hellip αn be nonnegative real numbers such that Σkαk = 1 Then for any real numbers x1 x2 hellip xn we have

Proof By induction on n For n = 1 we have α1= 1 and hence f(α1x1) leα1f(x1) trivially

L29October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L210October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Convexity

L211October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Induction

L212October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L213October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Lemma Let f R rarrR be a convex function and let α1 α2 hellip be nonnegative real numbers such that Σkαk= 1 Then for any real numbers x1 x2 hellip we have

assuming that these summations exist

L214October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 2: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L22October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Binary-search-tree sortTlarr empty ⊳Create an empty BSTfor i= 1 to n do TREE-INSERT (T A[i])Perform an inorder tree walk of T

ExampleA= [3 1 8 2 6 7 5]

Tree-walk time = O(n) but how long does it take to build the BST

L23October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST sortBST sort performs the same comparisons as quicksort but in a different order

The expected time to build the tree is asymptot-icallythe same as the running time of quicksort

L24October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Node depthThe depth of a node=the number of comparisons made during TREE-INSERT Assuming all input permutations are equally likely we have

Average node depth

(quicksort analysis)

(comparison to insert node i )

L25October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Expected tree heightBut average node depth of a randomly built BST = O(lg n)does not necessarily mean that its expected height is also O(lg n)(although it is)

Example

L26October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Height of a randomly built binary search tree

Outline of the analysisbull Prove Jensenrsquos inequality which says that f(E

[X]) leE[f(X)] for any convex function fand random variable X

bull Analyze the exponential height of a randomly built BST on n nodes which is the random variable Yn= 2Xn where Xn is the random variable denoting the height of the BST

bull Prove that 2E[Xn]leE[2Xn ] = E[Yn] = O(n3) and hence that E[Xn] = O(lg n)

L27October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convex functionsA function f RrarrR is convex if for all αβge0 such that α+ β= 1 we have

f(αx+ βy) leα f(x) + β f(y)

for all xyisinR

L28October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma

Lemma Let f R rarrR be a convex function and let α1 α2 hellip αn be nonnegative real numbers such that Σkαk = 1 Then for any real numbers x1 x2 hellip xn we have

Proof By induction on n For n = 1 we have α1= 1 and hence f(α1x1) leα1f(x1) trivially

L29October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L210October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Convexity

L211October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Induction

L212October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L213October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Lemma Let f R rarrR be a convex function and let α1 α2 hellip be nonnegative real numbers such that Σkαk= 1 Then for any real numbers x1 x2 hellip we have

assuming that these summations exist

L214October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 3: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L23October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST sortBST sort performs the same comparisons as quicksort but in a different order

The expected time to build the tree is asymptot-icallythe same as the running time of quicksort

L24October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Node depthThe depth of a node=the number of comparisons made during TREE-INSERT Assuming all input permutations are equally likely we have

Average node depth

(quicksort analysis)

(comparison to insert node i )

L25October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Expected tree heightBut average node depth of a randomly built BST = O(lg n)does not necessarily mean that its expected height is also O(lg n)(although it is)

Example

L26October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Height of a randomly built binary search tree

Outline of the analysisbull Prove Jensenrsquos inequality which says that f(E

[X]) leE[f(X)] for any convex function fand random variable X

bull Analyze the exponential height of a randomly built BST on n nodes which is the random variable Yn= 2Xn where Xn is the random variable denoting the height of the BST

bull Prove that 2E[Xn]leE[2Xn ] = E[Yn] = O(n3) and hence that E[Xn] = O(lg n)

L27October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convex functionsA function f RrarrR is convex if for all αβge0 such that α+ β= 1 we have

f(αx+ βy) leα f(x) + β f(y)

for all xyisinR

L28October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma

Lemma Let f R rarrR be a convex function and let α1 α2 hellip αn be nonnegative real numbers such that Σkαk = 1 Then for any real numbers x1 x2 hellip xn we have

Proof By induction on n For n = 1 we have α1= 1 and hence f(α1x1) leα1f(x1) trivially

L29October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L210October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Convexity

L211October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Induction

L212October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L213October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Lemma Let f R rarrR be a convex function and let α1 α2 hellip be nonnegative real numbers such that Σkαk= 1 Then for any real numbers x1 x2 hellip we have

assuming that these summations exist

L214October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 4: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L24October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Node depthThe depth of a node=the number of comparisons made during TREE-INSERT Assuming all input permutations are equally likely we have

Average node depth

(quicksort analysis)

(comparison to insert node i )

L25October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Expected tree heightBut average node depth of a randomly built BST = O(lg n)does not necessarily mean that its expected height is also O(lg n)(although it is)

Example

L26October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Height of a randomly built binary search tree

Outline of the analysisbull Prove Jensenrsquos inequality which says that f(E

[X]) leE[f(X)] for any convex function fand random variable X

bull Analyze the exponential height of a randomly built BST on n nodes which is the random variable Yn= 2Xn where Xn is the random variable denoting the height of the BST

bull Prove that 2E[Xn]leE[2Xn ] = E[Yn] = O(n3) and hence that E[Xn] = O(lg n)

L27October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convex functionsA function f RrarrR is convex if for all αβge0 such that α+ β= 1 we have

f(αx+ βy) leα f(x) + β f(y)

for all xyisinR

L28October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma

Lemma Let f R rarrR be a convex function and let α1 α2 hellip αn be nonnegative real numbers such that Σkαk = 1 Then for any real numbers x1 x2 hellip xn we have

Proof By induction on n For n = 1 we have α1= 1 and hence f(α1x1) leα1f(x1) trivially

L29October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L210October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Convexity

L211October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Induction

L212October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L213October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Lemma Let f R rarrR be a convex function and let α1 α2 hellip be nonnegative real numbers such that Σkαk= 1 Then for any real numbers x1 x2 hellip we have

assuming that these summations exist

L214October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 5: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L25October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Expected tree heightBut average node depth of a randomly built BST = O(lg n)does not necessarily mean that its expected height is also O(lg n)(although it is)

Example

L26October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Height of a randomly built binary search tree

Outline of the analysisbull Prove Jensenrsquos inequality which says that f(E

[X]) leE[f(X)] for any convex function fand random variable X

bull Analyze the exponential height of a randomly built BST on n nodes which is the random variable Yn= 2Xn where Xn is the random variable denoting the height of the BST

bull Prove that 2E[Xn]leE[2Xn ] = E[Yn] = O(n3) and hence that E[Xn] = O(lg n)

L27October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convex functionsA function f RrarrR is convex if for all αβge0 such that α+ β= 1 we have

f(αx+ βy) leα f(x) + β f(y)

for all xyisinR

L28October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma

Lemma Let f R rarrR be a convex function and let α1 α2 hellip αn be nonnegative real numbers such that Σkαk = 1 Then for any real numbers x1 x2 hellip xn we have

Proof By induction on n For n = 1 we have α1= 1 and hence f(α1x1) leα1f(x1) trivially

L29October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L210October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Convexity

L211October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Induction

L212October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L213October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Lemma Let f R rarrR be a convex function and let α1 α2 hellip be nonnegative real numbers such that Σkαk= 1 Then for any real numbers x1 x2 hellip we have

assuming that these summations exist

L214October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 6: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L26October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Height of a randomly built binary search tree

Outline of the analysisbull Prove Jensenrsquos inequality which says that f(E

[X]) leE[f(X)] for any convex function fand random variable X

bull Analyze the exponential height of a randomly built BST on n nodes which is the random variable Yn= 2Xn where Xn is the random variable denoting the height of the BST

bull Prove that 2E[Xn]leE[2Xn ] = E[Yn] = O(n3) and hence that E[Xn] = O(lg n)

L27October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convex functionsA function f RrarrR is convex if for all αβge0 such that α+ β= 1 we have

f(αx+ βy) leα f(x) + β f(y)

for all xyisinR

L28October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma

Lemma Let f R rarrR be a convex function and let α1 α2 hellip αn be nonnegative real numbers such that Σkαk = 1 Then for any real numbers x1 x2 hellip xn we have

Proof By induction on n For n = 1 we have α1= 1 and hence f(α1x1) leα1f(x1) trivially

L29October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L210October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Convexity

L211October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Induction

L212October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L213October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Lemma Let f R rarrR be a convex function and let α1 α2 hellip be nonnegative real numbers such that Σkαk= 1 Then for any real numbers x1 x2 hellip we have

assuming that these summations exist

L214October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 7: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L27October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convex functionsA function f RrarrR is convex if for all αβge0 such that α+ β= 1 we have

f(αx+ βy) leα f(x) + β f(y)

for all xyisinR

L28October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma

Lemma Let f R rarrR be a convex function and let α1 α2 hellip αn be nonnegative real numbers such that Σkαk = 1 Then for any real numbers x1 x2 hellip xn we have

Proof By induction on n For n = 1 we have α1= 1 and hence f(α1x1) leα1f(x1) trivially

L29October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L210October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Convexity

L211October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Induction

L212October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L213October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Lemma Let f R rarrR be a convex function and let α1 α2 hellip be nonnegative real numbers such that Σkαk= 1 Then for any real numbers x1 x2 hellip we have

assuming that these summations exist

L214October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 8: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L28October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma

Lemma Let f R rarrR be a convex function and let α1 α2 hellip αn be nonnegative real numbers such that Σkαk = 1 Then for any real numbers x1 x2 hellip xn we have

Proof By induction on n For n = 1 we have α1= 1 and hence f(α1x1) leα1f(x1) trivially

L29October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L210October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Convexity

L211October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Induction

L212October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L213October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Lemma Let f R rarrR be a convex function and let α1 α2 hellip be nonnegative real numbers such that Σkαk= 1 Then for any real numbers x1 x2 hellip we have

assuming that these summations exist

L214October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 9: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L29October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L210October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Convexity

L211October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Induction

L212October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L213October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Lemma Let f R rarrR be a convex function and let α1 α2 hellip be nonnegative real numbers such that Σkαk= 1 Then for any real numbers x1 x2 hellip we have

assuming that these summations exist

L214October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 10: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L210October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Convexity

L211October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Induction

L212October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L213October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Lemma Let f R rarrR be a convex function and let α1 α2 hellip be nonnegative real numbers such that Σkαk= 1 Then for any real numbers x1 x2 hellip we have

assuming that these summations exist

L214October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 11: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L211October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Induction

L212October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L213October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Lemma Let f R rarrR be a convex function and let α1 α2 hellip be nonnegative real numbers such that Σkαk= 1 Then for any real numbers x1 x2 hellip we have

assuming that these summations exist

L214October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 12: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L212October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Proof (continued)

Inductive step

Algebra

L213October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Lemma Let f R rarrR be a convex function and let α1 α2 hellip be nonnegative real numbers such that Σkαk= 1 Then for any real numbers x1 x2 hellip we have

assuming that these summations exist

L214October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 13: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L213October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Lemma Let f R rarrR be a convex function and let α1 α2 hellip be nonnegative real numbers such that Σkαk= 1 Then for any real numbers x1 x2 hellip we have

assuming that these summations exist

L214October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 14: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L214October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 15: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L215October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Convexity lemma infinite case

Proof By the convexity lemma for any nge1

Taking the limit of both sides

(and because the inequality is not strict)

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 16: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L216October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Definition of expectation

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 17: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L217October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)]

Proof

Convexity lemma (infinite case)

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 18: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L218October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Jensenrsquos inequality

Lemma Let f be a convex function and let X be a random variable Then f(E[X]) leE[f(X)] Proof

Tricky step but truemdashthink about it

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 19: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L219October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis of BST height

Let Xn be the random variable denoting the height of a randomly built binary search tree on n nodes and let Yn= 2Xn be its exponential heightIf the root of the tree has rank k then

Xn= 1 + max Xkndash1Xnndashk since each of the left and right subtrees of the root are randomly built Hence we have

Yn= 2middotmax Ykndash1Ynndashk

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 20: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L220October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Analysis (continued)

Define the indicator random variable Znk as

if the root has rank k

otherwise

Thus PrZnk= 1 = E[Znk] = 1n and

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 21: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L221October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Take expectation of both sides

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 22: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L222October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Linearity of expectation

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 23: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L223October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Independence of the rank of the root from the ranks of subtree roots

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 24: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L224October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

The max of two nonnegative numbers is at most their sum and E[Znk] = 1n

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 25: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L225October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Exponential height recurrence

Each term appears twice and reindex

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 26: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L226October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 27: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L227October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions Substitution

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 28: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L228October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Integral method

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 29: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L229October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Solve the integral

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 30: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L230October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Solving the recurrence

Use substitution to show that E[Yn] lecn3 for some positive constant c which we can pick sufficiently large to handle the initial conditions

Algebra

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 31: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L231October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

Jensenrsquos inequality since

f(x) = 2x is convex

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 32: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L232October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

Definition

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 33: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L233October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

What we just showed

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 34: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L234October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

The grand finale

Putting it all together we have

2E[Xn]leE[2Xn ]

= E[Yn]

lecn3

Taking the lg of both sides yields

E[Xn] le3lg n +O(1)

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 35: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L235October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem

Q Does the analysis have to be this hard

Q Why bother with analyzing exponential height

Q Why not just develop the recurrence on

Xn= 1 + maxXkndash1Xnndashk

directly

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 36: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L236October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Post mortem (continued)

A The inequalitymaxab lea+ b

provides a poor upper bound since the RHS approaches the LHS slowly as |andashb| increases The bound

max2a2b le2a+ 2b

allows the RHS to approach the LHS far more quickly as |andashb| increases By using the convexity of f(x) = 2x via Jensenrsquos inequality we can manipulate the sum of exponentials resulting in a tight analysis

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
Page 37: October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

L237October 17 2005 Copyrightcopy2001-5 Erik D Demaine and Charles E Leiserson

Thought exercises

bull See what happens when you try to do the analysis on Xn directly

bull Try to understand better why the proof uses an exponential Will a quadratic do

bull See if you can find a simpler argument (This argument is a little simpler than the one in the bookmdashI hope itrsquos correct)

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37