Newest Viewed Downloaded

Binary Search TreesDictionary Operations: search(key) insert(key, value) delete(key) Additional operations: ascend() IndexSearch(index) (indexed binary search tree) IndexDelete(index) (indexed binary search tree)

Binary Search Trees

Dictionary Operations: search(key) insert(key, value) delete(key) Additional operations: ascend() IndexSearch(index) (indexed binary search tree) IndexDelete(index) (indexed binary search tree)

Complexity Of Dictionary Operations search(), insert() and delete()

n is number of elements in dictionary

Complexity Of Other Operations ascend(), IndexSearch(index), IndexDelete(index)

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.

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.

The Operation search()

20 10 6 2 8 15 40 30 25 Complexity is O(height) = O(n), where n is number of nodes/elements.

The Operation insert()

20 10 6 2 8 15 40 30 25 Put a pair whose key is 35. 35

The Operation insert()

Put a pair whose key is 7. 20 10 6 2 8 15 40 30 25 35 7

The Operation insert()

20 10 6 2 8 15 40 30 25 Put a pair whose key is 18. 35 7 18

The Operation search()

20 10 6 2 8 15 40 30 25 Complexity of put() is O(height). 35 7 18

The Operation delete()

Three cases: Element is in a leaf. Element is in a degree 1 node. Element is in a degree 2 node.

delete From A Leaf

Remove a leaf element. key = 7 20 10 6 2 8 15 40 30 25 35 7 18

delete From A Leaf (contd.)

Remove a leaf element. key = 35 20 10 6 2 8 15 40 30 25 35 7 18

delete From A Degree 1 Node

Remove from a degree 1 node. key = 40 20 10 6 2 8 15 40 30 25 35 7 18

delete From A Degree 1 Node (contd.)

Remove from a degree 1 node. key = 15 20 10 6 2 8 15 40 30 25 35 7 18

delete From A Degree 2 Node

Remove from a degree 2 node. key = 10 20 10 6 2 8 15 40 30 25 35 7 18

delete From A Degree 2 Node

20 10 6 2 8 15 40 30 25 Replace with largest key in left subtree (or smallest in right subtree). 35 7 18

delete From A Degree 2 Node

20 10 6 2 8 15 40 30 25 Replace with largest key in left subtree (or smallest in right subtree). 35 7 18

delete From A Degree 2 Node

20 8 6 2 8 15 40 30 25 Replace with largest key in left subtree (or smallest in right subtree). 35 7 18

Showing 1 - 20 of 49 items Details

Name: 
mlec11-1
Author: 
Preferred Customer
Company: 
N/A
Description: 
Binary Search TreesDictionary Operations: search(key) insert(key, value) delete(key) Additional operations: ascend() IndexSearch(index) (indexed binary search tree) IndexDelete(index) (indexed binary search tree)
Tags: 
node | search | delete | binary | tree | from | degree | subtree
Created: 
6/17/1995 11:31:02 PM
Slides: 
49
Views: 
0
Downloads: 
0
Rating: 
0


> Comment



Share this presentation
|

Comments

Share this presentation:

|
Sitemap