麻省理工学院:《算法导论》(英文版) Lecture 9 Prof charles e. leiserson

Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 9 Prof charles e. leiserson
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 9 Prof. Charles E. Leiserson

Binary-search-tree sort T< b Create an empty bst for i=l to n do TREe-INSERT(T, AiD Perform an inorder tree walk of t Example A=[3182675] 8 ree-walk time =O(n but how long does it take to build the bst c 2001 by Charles E Leiserson Introduction to Agorithms Day 17 L9.2
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 17 L9.2 33 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 = [3 1 8 2 6 7 5] 11 88 22 66 55 77 Tree-walk time = O(n), but how long does it take to build the BST?

Analysis of bst sort BST sort performs the same comparisons as quicksort, but in a different order 3182675 8)675 675 The expected time to build the tree is asymptot ically the same as the running time of quicksort c 2001 by Charles E Leiserson Introduction to Agorithms Day 17 L9.3
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 17 L9.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 5 7 The expected time to build the tree is asymptotically the same as the running time of quicksort

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 E∑( comparisons to insert no lO(nlgn) (quicksort analysis O(gn) c 2001 by Charles E Leiserson Introduction to Agorithms Day 17 L9.4
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 17 L9.4 Node depth The depth of a node = the number of comparisons made during TREE-INSERT. Assuming all input permutations are equally likely, we have ( ) (lg ) ( lg ) 1 #comparisons to insert node 1 1 O n O n n n E i n n i = = = ∑= Average node depth . (quicksort analysis)

Expected tree height But, average node depth of a randomly built BST=O(g n) does not necessarily mean that its expected height is also O(g n)(although it is) Example ≤1gn Ave.deph≤1nlgn+nn O(gn) c 2001 by Charles E Leiserson Introduction to Agorithms Day 17 L9.5
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 17 L9.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 h = n (lg ) 2 lg 1 O n n n n n n = ⋅ Ave. depth ≤ ⋅ +

Height of a randomly built binary search tree Outline of the analysis: Prove jensen’ s inequali的, which says that feDs(XI 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 y= 2An where X is the random variable denoting the height of the bst Prove that 2ELAnl EJ2Xn1=E[Ym =O(n) and hence that EXn=O(g n) c 2001 by Charles E Leiserson Introduction to Algorithms Day 17 L9.6
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 17 L9.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 Yn = 2Xn, where Xn is the random variable denoting the height of the BST. • Prove that 2E[Xn] ≤ E[2Xn ] = E[Yn] = O(n3), and hence that E[Xn] = O(lg n). Outline of the analysis:

Convex functions A functionf:R>R is convex if for all a,B≥0 such that a+β=1, we have fax+阝y)≤o(x)+B/f orax,y∈ R f afx)+ B) f fax+阝y) x ax+ B c 2001 by Charles E Leiserson Introduction to Agorithms Day 17 L9.7
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 17 L9.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. αx + βy αf(x) + βf(y) f(αx + βy) x y f(x) f(y) f

Convexity lemma Lemma Let f: R>R be a convex function an nd let (ap,a2,.,an) be a set of nonnegative constants such that 2la= 1. Then, for any set x,x2,.,xn) of real numbers, we have ∑axk|s∑a/(x) k=1 k=1 Proof By induction on n. For n=1, we have I=l, and hence fax,sav( trivially c 2001 by Charles E Leiserson Introduction to Agorithms Day 17 L9.8
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 17 L9.8 Convexity lemma Lemma. Let f : R → R be a convex function, and let {α1, α2 , …, αn} be a set of nonnegative constants such that ∑k αk = 1. Then, for any set {x1, x2, …, xn} of real numbers, we have ( ) 1 1 ∑ ∑ = = ≤ nk k k nk k k f α x α f x Proof. By induction on n. For n = 1, we have α1 = 1, and hence f(α1x1) ≤ α1f(x1) trivially.

Proof (continued) Inductive step kkk= n-n +(1 k X k=1 k n algebra c 2001 by Charles E Leiserson Introduction to Agorithms Day 17 L9.9
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 17 L9.9 Proof (continued) − = + − ∑ ∑− = =1 1 11 (1 )nk k n k n n n nk k k f x f x x α α α α α Inductive step: Algebra

Proof (continued) Inductive step k k k anIn+(l-a n n k=1 ≤an(x)+(-an)∑,“xk k=1 Convexity c 2001 by Charles E Leiserson Introduction to Agorithms Day17L9.10
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 17 L9.10 Proof (continued) − ≤ + − − = + − ∑ ∑ ∑ − = − = = 1 1 1 1 1 1 ( ) (1 ) 1 (1 ) n k k n k n n n n k k n k n n n n k k k f x f x f x f x x α α α α α α α α α Inductive step: Convexity
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 麻省理工学院:《算法导论》(英文版) Lecture 8 Prof charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 7 Prof charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 6 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版)Lecture 5 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版)Lecture 4 Prof. charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 3 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 2 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture Prof. Charles E. Leiserson.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)实验二 波形输入与仿真实现.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)综合、设计性实验指导书.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)封面.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)附录GW48EDA系统使用说明.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)实验一 可编程ASIC使用初步.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)实验五 A/D采样电路设计.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)实验四 只读存储器设计.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)实验三 序列信号发生器与序列信号检测器的设计.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)实验六 数字电压表设计.pdf
- 《数字平面艺术设计》课程教学资源(试卷习题)试题库.doc
- 华中科技大学:《MATLAB语言与控制系统仿真》课程教学资源(PPT课件讲稿)第四章 控制系统的分析方法.ppt
- 华中科技大学:《MATLAB语言与控制系统仿真》课程教学资源(PPT课件讲稿)第五章 SIMULINK仿真基础.ppt
- 麻省理工学院:《算法导论》(英文版) Lecture 10 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 11 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 12 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版)Lecture 13 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 14 Prof charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 15 Prof charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 16 Prof charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版)Lecture 17 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 18 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 19 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 20 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 21 Prof charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 22 Prof charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 23 Prof charles e. leiserson.pdf
- 《计算机三级网络技术》第一章 计算机基础知识.doc
- 《计算机三级网络技术》第七章 电子商务和电子政务.doc
- 《计算机三级网络技术》第三章 局域网基础.doc
- 《计算机三级网络技术》第二章 网络基本概念.doc
- 《计算机三级网络技术》第五章 因特网基础.doc
- 《计算机三级网络技术》第八章 网络技术展望.doc