![Page 1: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/1.jpg)
CS 171: Introduction to Computer Science II
Binary Search Trees (cont.)
![Page 2: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/2.jpg)
Binary Search Trees
• Definitions and terminologies
• Search and insert
• Traversal
• Ordered operations
• Delete• Delete
![Page 3: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/3.jpg)
![Page 4: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/4.jpg)
![Page 5: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/5.jpg)
![Page 6: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/6.jpg)
Traversal
• In-order
–Left subtree, current node, right subtree
• Pre-order
–Current node, left subtree, right subtree
• Post-order• Post-order
–Left subtree, right subtree, current node
![Page 7: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/7.jpg)
![Page 8: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/8.jpg)
![Page 9: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/9.jpg)
• In-order
A C E H M R S X
• Pre-order?
• Post-order?
Traversal
![Page 10: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/10.jpg)
• In-order
A C E H M R S X
• Pre-order
S E A C R H M X
• Post-order
Traversal
• Post-order
C A M H R E X S
• How to visit the nodes in
descending order?
• What’s the use of pre-order and
post-order traversal?
![Page 11: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/11.jpg)
Expression Tree
• Post-order traversal results in postfix notation
• Pre-order traversal results in prefix notation
![Page 12: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/12.jpg)
Binary Search Trees
• Definitions and terminologies
• Search and insert
• Traversal
• Ordered operations
–Minimum and maximum–Minimum and maximum
–Rank: how many keys < k?
–Select: key of given rank
• Delete
![Page 13: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/13.jpg)
![Page 14: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/14.jpg)
![Page 15: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/15.jpg)
![Page 16: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/16.jpg)
![Page 17: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/17.jpg)
![Page 18: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/18.jpg)
Binary Search Trees
• Definitions and terminologies
• Search and insert
• Traversal
• Ordered operations
• Delete• Delete
–Delete minimum and maximum
–Delete a given key
![Page 19: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/19.jpg)
Delete minimum
![Page 20: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/20.jpg)
![Page 21: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/21.jpg)
![Page 22: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/22.jpg)
![Page 23: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/23.jpg)
![Page 24: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/24.jpg)
![Page 25: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/25.jpg)
![Page 26: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/26.jpg)
![Page 27: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/27.jpg)
![Page 28: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/28.jpg)
![Page 29: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/29.jpg)
![Page 30: CS171:Introduction to Computer Science II Binary Search ... · Binary search trees Definition. A BST is a binary tree in symmetric order. root a left link right child of root A binary](https://reader034.vdocuments.site/reader034/viewer/2022042222/5ec962bc8f6a78529a1d93c7/html5/thumbnails/30.jpg)
Binary Search Trees
• Definitions and terminologies
• Search and insert
• Traversal
• Ordered operations
• Delete• Delete
• Balanced search trees (Amy Shannon)