# lec26a - Lecture 26 Welcome back Binary search trees 15.1-5...

This preview shows pages 1–15. Sign up to view the full content.

Lecture 26 Welcome back! Binary search trees 15.1-5

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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 Dictionary Operations get(), put() and remove() Data Structure Worst Case Expected Hash Table O(n) O(1) Binary Search Tree O(n) O(log n) Balanced Binary Search Tree O(log n) O(log n) n is number of elements in dictionary

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Complexity Of Other Operations ascend(), get(index), remove(index) Data Structure ascend get and remove Hash Table O(D + n log n) O(D + n log n) Indexed BST O(n) O(n) Indexed Balanced 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 left subtree of x are smaller than that in x . For every node x , all keys in the right subtree of x are greater than that in x .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example Binary Search Tree 20 10 6 2 8 15 40 30 25 Only keys are shown.
The Operation ascend() 20 10 6 2 8 15 40 30 25 Do an inorder traversal. O(n) time.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
The Operation get() 20 10 6 2 8 15 40 30 25 Get pair whose key is 8 8
The Operation get() 20 10 6 2 8 15 40 30 25 Get pair whose key is 8 8

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
The Operation get() 20 10 6 2 8 15 40 30 25 Get pair whose key is 8 8
The Operation get() 20 10 6 2 8 15 40 30 25 Get pair whose key is 8 8

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
The Operation get() 20 10 6 2 8 15 40 30 25 Get pair whose key is 8 8!
The Operation get() 20 10 6 2 8 15 40 30 25 Complexity is O(height) = O(n) , where n is number of nodes/elements.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
20 10 6 2 8 15 40 30 25 Put a pair whose key is 35 . 35
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 60

lec26a - Lecture 26 Welcome back Binary search trees 15.1-5...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online