09-Randomly-Built-BST

# 09-Randomly-Built-BST - Algorithms LECTURE 9 Randomly built...

This preview shows pages 1–8. Sign up to view the full content.

Algorithms L7.1 Professor Ashok Subramanian L ECTURE 9 Randomly built binary search trees Expected node depth Analyzing height Convexity lemma Jensen’s inequality Exponential height Post mortem Algorithms

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Algorithms L7.2 3 Binary-search-tree sort T Create an empty BST for i = 1 to n do T REE -I NSERT ( T , A [ i ]) Perform an inorder tree walk of T . Example: A = [3 1 8 2 6 7 5] 8 1 2 6 5 7 Tree-walk time = O ( n ) , but how long does it take to build the BST?
Algorithms L7.3 Analysis of BST sort BST sort performs the same comparisons as quicksort, but in a different order! 3 1 8 2 6 7 5 1 2 8 6 7 5 2 6 7 5 7 5 The expected time to build the tree is asymptot- ically the same as the running time of quicksort.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Algorithms L7.4 Node depth The depth of a node = the number of comparisons made during T REE -I NSERT . Assuming all input permutations are equally likely, we have ( 29 ) (lg ) lg ( 1 node insert to s comparison # 1 1 n O n n O n i E n n i = = = = Average node depth . (quicksort analysis)
Algorithms L7.5 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. lg n n h = ) (lg 2 lg 1 n O n n n n n = + Ave. depth

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Algorithms L7.6 Height of a randomly built binary search tree Prove Jensen’s inequality , which says that f ( E [ X ]) E [ f ( X )] for any convex function f and random variable X . Analyze the exponential height of a randomly built BST on n nodes, which is the random variable Y = 2 , where X is the random Outline of the analysis:
L7.7 Convex functions A function f : R R is convex if for all α , β 0 such that α + β = 1 , we have f ( α x + β y ) α f ( x ) + β f ( y ) for all x , y R . α

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 37

09-Randomly-Built-BST - Algorithms LECTURE 9 Randomly built...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}