Docsity

Lecture Slides on Binary Search Tree | COP 3530, Study notes of Data Structures and Algorithms

Partial preview of the text

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.

The Operation put()

Put a pair whose key is 35.

The Operation put()

Put a pair whose key is 35.

The Operation put()

Put a pair whose key is 35.

The Operation put()

Put a pair whose key is 7.

The Operation put()

Put a pair whose key is 7.