Download presentation
Presentation is loading. Please wait.
1
Data Structures: Binary Search Trees
By: A. H. Abdul Hafez DS, by Dr. A.H. Abdul Hafez, CE Dept. HKU January 1, 2019
2
Outlines Dictionary Definition of a binary search tree
Operations on BST Search Insert Delete End DS, by Dr. A.H. Abdul Hafez, CE Dept. HKU January 1, 2019
3
Dictionary An abstract data type that support operations insert, delete, and search is called a dictionary. It has applications in a numerous algorithms. Comparison methods vs. direct access methods. Binary search tree is example of the former while hashing tables are example of the later. Example: Application to search n a library. DS, by Dr. A.H. Abdul Hafez, CE Dept. HKU January 1, 2019
4
Definition of Binary Search Trees BSTs
DS, by Dr. A.H. Abdul Hafez, CE Dept. HKU January 1, 2019
5
Operations on BSTs BST support the operations search, insert, and delete; both by key value and by rank. By key values: find en element with key = x. insert after key=x, and delete element with key=x. By rank: find the fifth smallest element, delete …., insert and determine the rank. Tree in (a) is not BST DS, by Dr. A.H. Abdul Hafez, CE Dept. HKU January 1, 2019
6
Searching a BST Recursive search of a binary search tree.
DS, by Dr. A.H. Abdul Hafez, CE Dept. HKU January 1, 2019
7
Searching a BST Iterative search of a binary search tree.
DS, by Dr. A.H. Abdul Hafez, CE Dept. HKU January 1, 2019
8
Searching a BST Searching a binary search tree by rank.
DS, by Dr. A.H. Abdul Hafez, CE Dept. HKU January 1, 2019
9
Insertion into a BST To insert an element x, we must first verify that its key is different from those of existing elements. To do this, a search is carried out. If the search is unsuccessful, then the element is inserted at the point the search terminated. DS, by Dr. A.H. Abdul Hafez, CE Dept. HKU January 1, 2019
10
Insertion into a BST DS, by Dr. A.H. Abdul Hafez, CE Dept. HKU
January 1, 2019
11
Deletion from a BST To delete a leaf node, set the left/right-child field of its parent to 0. To delete non-leaf element that has only one child, change the pointer from the parent node to the single child node. DS, by Dr. A.H. Abdul Hafez, CE Dept. HKU January 1, 2019
12
The end of the Lecture Thanks for your time Questions are welcome
DS, by Dr. A.H. Abdul Hafez, CE Dept. HKU January 1, 2019
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.