AVL trees Flashcards

1
Q

Describe the AVL tree structure.

A

The AVL tree is similar to a binary search tree.

We want to make sure the tree is balanced - the height should be as low as possible.

To achieve this, we keep track of the height of each subtree. By taking the difference in these values, we find what’s called the balance factor. If this is outside the interval [-1, 1], the tree is unbalanced and we need to perform appropriate rotations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The subtrees can be in four different states. Describe these.

A

Follow this chart: http://imgur.com/a/6fd0P

The tree can be weighted to the left:

  • LL (Left child, left child’s left child)
  • LR (Left child, left child’s right child)

The tre can be weighted to the right, which are mirrored left-weighted problems.

  • RR (Right child, right child’s right child)
  • RL (Right child, right child’s left child)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you do a left or right rotation? (LL or RR)

A

http://imgur.com/a/od9Rm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you perform a LR or RL rotation?

A

http://imgur.com/a/BVWR8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When do we need to perform rotations?

A

When a node’s balance factor is something besides is outside the interval [-1, 1].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly