Docsity

Advanced Data Structures: Trees, Treaps, k-d Trees, Suffix Trees, and Bloom Filters, Exams of Data Structures and Algorithms

Partial preview of the text

Download Advanced Data Structures: Trees, Treaps, k-d Trees, Suffix Trees, and Bloom Filters and more Exams Data Structures and Algorithms in PDF only on Docsity!

Advanced Data

Structures

Insertion Order Matters

●

Suppose we create a BST of numbers in

this order:

4, 2, 1, 3, 6, 5, 7

4

2 6

Tree Terminology

●

The height of a tree is the number of

nodes in the longest path from the root

to a leaf.

4

2 6

Tree Terminology

●

The height of a tree is the number of

nodes in the longest path from the root

to a leaf.

1 2 3 4 5 6

Tree Rotations

●

One common way of keeping tree heights

low is to reshape the BST when it gets

too high.

●

One way to accomplish this is a tree

rotation , which locally rearranges

nodes.

Tree Rotations

B

A

B

<A

A

<B

B

A

B

<A

A

<B

Rotate Right

Rotate Left

1

2

3

4

5

1

2

3

4

5