Download Lecture Slides on Binary Search Tree | COP 3530 and more Study notes Data Structures and Algorithms in PDF only on Docsity!
Lecture
• Welcome back! • Binary search trees • 15.1-
Binary Search Trees
• Dictionary Operations:
^
get(key)
^
put(key, value)
^
remove(key)
• Additional operations:
^
ascend()
^
get(index) (indexed binary search tree)
^
remove(index) (indexed binary search tree)
Complexity Of Other Operations
ascend(), get(index), remove(index)^ Data Structure ascend
get andremove
Hash Table
O
(D + n lo
g^
n)
O
(D + n lo
g^
n)
Indexed BST
O(n)
O(n)
IndexedBalanced BST
O(n)
O(log n)
D is number of buckets
Definition Of Binary Search Tree • A binary tree. • Each node has a (key, value) pair. • For every node x, all keys in the leftsubtree of x are smaller than that in x. • For every node x, all keys in the rightsubtree of x are greater than that in x.
The Operation ascend()
Do an inorder traversal. O(n) time.
The Operation get()
Get pair whose key is 8
The Operation get()
8 Get pair whose key is 8
The Operation get()
Get pair whose key is 8
The Operation get()
Complexity is O(height) = O(n), where n isnumber of nodes/elements.