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.

Slides:



Advertisements
Similar presentations
Mathematical Preliminaries
Advertisements

한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
2. Getting Started Heejin Park College of Information and Communications Hanyang University.
Introduction to Algorithms
October 31, 2005Copyright © by Erik D. Demaine and Charles E. LeisersonL13.1 Introduction to Algorithms LECTURE 11 Amortized Analysis Dynamic tables.
Introduction to Algorithms
Angstrom Care 培苗社 Quadratic Equation II
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (Parallel Algorithms) Robin Pomplun.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
UNITED NATIONS Shipment Details Report – January 2006.
Introduction to Algorithms 6.046J/18.401J
Introduction to Algorithms 6.046J/18.401J
Introduction to Algorithms 6.046J/18.401J
Introduction to Algorithms 6.046J/18.401J/SMA5503
Introduction to Algorithms
© 2001 by Charles E. Leiserson Introduction to AlgorithmsDay 18 L10.1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 10 Prof. Erik Demaine.
© 2001 by Charles E. Leiserson Introduction to AlgorithmsDay 17 L9.1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 9 Prof. Charles E. Leiserson.
©2001 by Charles E. Leiserson Introduction to AlgorithmsDay 9 L6.1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 6 Prof. Erik Demaine.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Excel Functions. Part 1. Introduction 2 An Excel function is a formula or a procedure that is performed in the Visual Basic environment, outside the.
Comp 122, Spring 2004 Order Statistics. order - 2 Lin / Devi Comp 122 Order Statistic i th order statistic: i th smallest element of a set of n elements.
David Luebke 1 6/1/2014 CS 332: Algorithms Medians and Order Statistics Structures for Dynamic Sets.
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Ack: Several slides from Prof. Jim Anderson’s COMP 202 notes.
Recurrences : 1 Chapter 3. Growth of function Chapter 4. Recurrences.
EU market situation for eggs and poultry Management Committee 20 October 2011.
Copyright © 2013, 2009, 2005 Pearson Education, Inc.
Bellwork Do the following problem on a ½ sheet of paper and turn in.
2 |SharePoint Saturday New York City
Green Eggs and Ham.
VOORBLAD.
David Luebke 1 8/25/2014 CS 332: Algorithms Red-Black Trees.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Squares and Square Root WALK. Solve each problem REVIEW:
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
© 2012 National Heart Foundation of Australia. Slide 2.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
10 -1 Chapter 10 Amortized Analysis A sequence of operations: OP 1, OP 2, … OP m OP i : several pops (from the stack) and one push (into the stack)
Analyzing Genes and Genomes
1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
CSE Lecture 17 – Balanced trees
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Energy Generation in Mitochondria and Chlorplasts
1 Decidability continued…. 2 Theorem: For a recursively enumerable language it is undecidable to determine whether is finite Proof: We will reduce the.
Introduction to Algorithms Jiafen Liu Sept
Introduction to Algorithms Prof. Charles E. Leiserson
Presentation transcript:

October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary search trees Expected node depth Analyzing eight Convexity lemma Jensens inequality Exponential height Post mortem Prof. Erik Demaine

L2.2October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Binary-search-tree sort T Create an empty BST for i= 1 to n do TREE-INSERT (T, A[i]) Perform an inorder tree walk of T. Example: A= [ ] Tree-walk time = O(n), but how long does it take to build the BST?

L2.3October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Analysis of BST sort BST 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.

L2.4October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Node depth The 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 )

L2.5October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Expected tree height But, 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.

L2.6October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Height of a randomly built binary search tree Outline of the analysis: Prove Jensens inequality, which says that f(E[X]) E[f(X)] for any convex function fand random variable X. Analyze the exponential height of a randomly built BST on n nodes, which is the random variable Yn= 2 Xn, where Xn is the random variable denoting the height of the BST. Prove that 2 E[Xn]E[2Xn ] = E[Yn] = O(n3), and hence that E[Xn] = O(lg n).

L2.7October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Convex functions A function f : RR is convex if for all α,β0 such that α+ β= 1, we have f(αx+ βy) α f(x) + β f(y) for all x,y R.

L2.8October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Convexity lemma Lemma. Let f : R R be a convex function, and let α 1, α 2, …, α n be nonnegative real numbers such that Σ k α k = 1. Then, for any real numbers x 1, x 2, …, x n, we have Proof. By induction on n. For n = 1, we have α 1 = 1, and hence f(α 1 x 1 ) α 1 f(x 1 ) trivially.

L2.9October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Proof (continued) Inductive step: Algebra.

L2.10October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Proof (continued) Inductive step: Convexity.

L2.11October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Proof (continued) Inductive step: Induction.

L2.12October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Proof (continued) Inductive step: Algebra.

L2.13October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Convexity lemma: infinite case Lemma. Let f : R R be a convex function, and let α 1, α 2, …, be nonnegative real numbers such that Σ k α k = 1. Then, for any real numbers x 1, x 2, …, we have assuming that these summations exist.

L2.14October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Convexity lemma: infinite case Proof. By the convexity lemma, for any n1,

L2.15October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Convexity lemma: infinite case Proof. By the convexity lemma, for any n1, Taking the limit of both sides (and because the inequality is not strict):

L2.16October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Jensens inequality Lemma. Let f be a convex function, and let X be a random variable. Then, f(E[X]) E[f(X)]. Proof. Definition of expectation.

L2.17October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Jensens inequality Lemma. Let f be a convex function, and let X be a random variable. Then, f(E[X]) E[f(X)]. Proof. Convexity lemma (infinite case).

L2.18October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Jensens inequality Lemma. Let f be a convex function, and let X be a random variable. Then, f(E[X]) E[f(X)]. Proof. Tricky step, but truethink about it.

L2.19October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Analysis of BST height Let X n be the random variable denoting the height of a randomly built binary search tree on n nodes, and let Y n = 2X n be its exponential height. If the root of the tree has rank k, then X n = 1 + max {X k –1,X n –k}, since each of the left and right subtrees of the root are randomly built. Hence, we have Y n = 2·max {Y k –1,Y n –k}.

L2.20October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Analysis (continued) Define the indicator random variable Z nk as if the root has rank k, otherwise. Thus, Pr{Z nk = 1} = E[Z nk ] = 1/n, and

L2.21October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Exponential height recurrence Take expectation of both sides.

L2.22October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Exponential height recurrence Linearity of expectation.

L2.23October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Exponential height recurrence Independence of the rank of the root from the ranks of subtree roots.

L2.24October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Exponential height recurrence The max of two nonnegative numbers is at most their sum, and E[Z nk ] = 1/n.

L2.25October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Exponential height recurrence Each term appears twice, and reindex.

L2.26October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Solving the recurrence Use substitution to show that E[Y n ] cn 3 for some positive constant c, which we can pick sufficiently large to handle the initial conditions.

L2.27October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Solving the recurrence Use substitution to show that E[Y n ] cn 3 for some positive constant c, which we can pick sufficiently large to handle the initial conditions. Substitution.

L2.28October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Solving the recurrence Use substitution to show that E[Y n ] cn 3 for some positive constant c, which we can pick sufficiently large to handle the initial conditions. Integral method.

L2.29October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Solving the recurrence Use substitution to show that E[Y n ] cn 3 for some positive constant c, which we can pick sufficiently large to handle the initial conditions. Solve the integral.

L2.30October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Solving the recurrence Use substitution to show that E[Y n ] cn 3 for some positive constant c, which we can pick sufficiently large to handle the initial conditions. Algebra.

L2.31October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson The grand finale Putting it all together, we have 2 E[Xn]E[2 Xn ] Jensens inequality, since f(x) = 2 x is convex.

L2.32October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson The grand finale Putting it all together, we have 2 E[Xn]E[2 Xn ] = E[Y n ] Definition.

L2.33October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson The grand finale Putting it all together, we have 2 E[Xn]E[2 Xn ] = E[Y n ] cn 3. What we just showed.

L2.34October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson The grand finale Putting it all together, we have 2 E[Xn]E[2 Xn ] = E[Y n ] cn 3. Taking the lg of both sides yields E[X n ] 3lg n +O(1).

L2.35October 17, 2005 Copyright© 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 X n = 1 + max{X k –1,X n –k} directly?

L2.36October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Post mortem (continued) A. The inequality max{a,b} a+ b. provides a poor upper bound, since the RHS approaches the LHS slowly as |a–b| increases. The bound max{2 a,2 b } 2 a + 2 b allows the RHS to approach the LHS far more quickly as |a–b| increases. By using the convexity of f(x) = 2 x via Jensens inequality, we can manipulate the sum of exponentials, resulting in a tight analysis.

L2.37October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson Thought exercises See what happens when you try to do the analysis on X n directly. Try to understand better why the proof uses an exponential. Will a quadratic do? See if you can find a simpler argument. (This argument is a little simpler than the one in the bookI hope its correct!)