复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 06 Binary search trees

Data Structures and Algorithm Xiaoqing Zheng Zhengxq@fudan.edu.cn
Data Structures and Algorithm Data Structures and Algorithm Xiaoqing Zheng zhengxq@fudan.edu.cn

Trees(max heap PARENT(O 16 return i/2 LEFT( 14 10 return 2 5 6 8 9 3 RIGHTO return 2i+1 2 4 161410879324
T h) rees (max heap ) 1 PARENT ( i ) 16 PARENT ( i ) return ⎢⎣ i / 2⎥⎦ 1 2 3 14 10 LEFT ( i ) return 2 i 2 3 8 7 9 3 RIGHT ( i ) return 2 i + 1 4 56 7 return 2 i + 1 8 9 10 2 4 1 16 14 10 8 7 9 3 2 4 1

Binary trees 7o0 Not array!
Binary trees root[T] / / / / / / / / / / / / / Not array!

Binary search tree Each node x has keyI] Pointers 12 left 6 right plx] 7 8
Binary S hT earc ree y Each node x has: 9 5 12 – key[x] – Pointers: 1 6 y left[x] y right[x] 7 y right[x] y p[x] 8

Binary search tree Property: for any node x For all nodes v in the left subtree ofx 12 keyy]≤key{x For all nodes y in the right subtree of x 6 keyy]≥key{x 7 Given a set of keys, iS bst for those keys unique? 8
Binary S hT earc ree 9 y Property: for any node x: – For all nodes y in the left 5 12 For all nodes y in the left subtree of x: key[y] ≤ key[x] 1 6 key[y] ≤ key[x] – For all nodes y in the right subtree of x: 7 subtree of x: key[y] ≥ key[x] 8 y Given a set of keys, is BST for those keys unique? 8

No uniqueness 7 5 9 12 6 8 12 6 7 8
No uniqueness 7 9 5 12 5 9 1 6 8 12 1 6 7 8

What can we do given bst Sort INORDER-TREE-WALK(x) 1.ifx≠NII 2. then INORDER-TREE-WaLK(left[xD print keylxI INORDER-TREE-WALK(rightXD A preorder tree walk prints the root before the values in either subtree, and a postorder tree walk prints the root after the values in its subtrees
Wh d ST ? at can we do given BST ? Sort ! INORDER -TREE -WALK (x ) 1. if x ≠ NIL 2. then INORDER INORDER -TREE -WALK (l ft e [ x]) 3. print key [ x ] 4 INORDER 4. INORDER -TREE -WALK ( ri ht g [ ]) x A preord t lk er tree walk p ri t th t b f th i n ts the roo t b e fore the values in either subtree, and a postorder tree walk p ri t th t ft th l i it bt i n ts the roo t after the va lues in its subtrees

Sort
S ? ort 9 5 12 1 6 7 8

Sort
S ? ort 9 5 12 1 6 7 8

Sort
S ? ort 9 5 12 1 6 7 8
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 05 Hash tables.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 04 Soring.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 03 Basic data structure - Elementary data structures.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 02 Divide-and-conquer design paradigm.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 01 Algorithm analysis and recurrences.pdf
- 复旦大学:《数据结构与算法设计》综合项目_Project3. All-pairs shortest path.pdf
- 复旦大学:《数据结构与算法设计》综合项目_Project2. English-Chinese dictionary based on binary search tree.pdf
- 复旦大学:《数据结构与算法设计》综合项目_Project1. Combining quicksort with insertion sort.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 8. String Matching.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 7. Single-Source Shortest Paths.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 6. Greedy Algorithms.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 5. Red-Black Tree.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 4. Binary Search Trees.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 3. Hash Tables.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 2. Divide and Conquer.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 1. Stack.pdf
- 复旦大学:《数据结构与算法设计》考试样卷_2009-2010年度A卷(答案).pdf
- 复旦大学:《数据结构与算法设计》考试样卷_2009-2010年度A卷(试卷).pdf
- 复旦大学:《计算机网络 Computer Networking》课程教学资源(PPT课件讲稿)移动商务介绍(概念及其特点、移动商务与电子商务、价值链及商业模式).ppt
- 复旦大学:《计算机网络 Computer Networking》课程教学资源(PPT课件讲稿)无线局域网补充删节版本.ppt
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 07 Amortized analysis.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 08 Dynamic programming.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 09 Greedy algorithms.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 10 Graph algorithms.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 11 String Matching.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 12 NP-complete problems.pdf
- 复旦大学:《计算机网络 Computer Networking》课程教学资源_考试样卷.doc
- 复旦大学:《计算机网络 Computer Networking》课程教学资源_各章节练习题.docx
- 复旦大学:《计算机网络 Computer Networking》课程教学资源_考试样卷.doc
- 《计算机网络》课程教学资源(参考文献)END-TO-END ARGUMENTS IN SYSTEM DESIGN.pdf
- 《计算机网络》课程教学资源(参考文献)The Design Philosophy of the DARPA Internet Protocols.pdf
- 《计算机网络》课程教学资源(参考文献)Interdomain Internet Routing.pdf
- 《计算机网络》课程教学资源(参考文献)Stable Internet Routing Without Global Coordination.pdf
- 《计算机网络》课程教学资源(参考文献)9e5f3e30-0aac-407f-b55f-4b04f28fcc05.pdf
- 《计算机网络》课程教学资源(参考文献)Congestion Avoidance and Control.pdf
- 《计算机网络》课程教学资源(参考文献)Random Early Detection Gateways for Congestion Avoidance.pdf
- 《计算机网络》课程教学资源(参考文献)Congestion Control for High Bandwidth-Delay Product Networks.pdf
- 《计算机网络》课程教学资源(参考文献)Analysis and Simulation of a Fair Queueing Algorithm.pdf
- 《计算机网络》课程教学资源(参考文献)Core-St at eless Fair Queueing:Achieving Approximately Fair Bandwidth Allocations in High Speed Networks.pdf
- 《计算机网络》课程教学资源(参考文献)Fundamental Design Issues for the Future Internet.pdf