lec26a - Lecture 26 Welcome back! Binary search trees...

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

View Full Document Right Arrow Icon
Lecture 26 Welcome back! Binary search trees 15.1-5
Background image of page 1

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

View Full DocumentRight Arrow Icon
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)
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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 .
Background image of page 5

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

View Full DocumentRight Arrow Icon
Example Binary Search Tree 20 10 6 2 8 15 40 30 25 Only keys are shown.
Background image of page 6
The Operation ascend() 20 10 6 2 8 15 40 30 25 Do an inorder traversal. O(n) time.
Background image of page 7

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

View Full DocumentRight Arrow Icon
The Operation get() 20 10 6 2 8 15 40 30 25 Get pair whose key is 8 8
Background image of page 8
The Operation get() 20 10 6 2 8 15 40 30 25 Get pair whose key is 8 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
The Operation get() 20 10 6 2 8 15 40 30 25 Get pair whose key is 8 8
Background image of page 10
The Operation get() 20 10 6 2 8 15 40 30 25 Get pair whose key is 8 8
Background image of page 11

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

View Full DocumentRight Arrow Icon
The Operation get() 20 10 6 2 8 15 40 30 25 Get pair whose key is 8 8!
Background image of page 12
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.
Background image of page 13

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

View Full DocumentRight Arrow Icon
20 10 6 2 8 15 40 30 25 Put a pair whose key is 35 . 35
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 60

lec26a - Lecture 26 Welcome back! Binary search trees...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online