Ch 7: Balanced Trees II Flashcards

1
Q

what is an AVL tree?

A

a BST with a height balance property and specific operations to rebalance the tree when a node is inserted or removed

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

when is a tree height-balanced?

A

for any node, the height of the node’s left and right subtrees differ by only 0 or 1

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

what is a balance factor?

A

left subtree minus the right subtree height (which is 0,1, or -1 in an AVL tree)

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

what is the average AVL height?

A

O(logn)

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

does an AVL ensure minimum height?

A

no but the height is no more than 1.5 the minimum of a binary tree height

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

what is runtime complexity for determining the balance factor and why?

A

O(1) because each node contains its height

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

what does a balance factor of 2 or -2 indicate?

A

rotation

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

what are the 4 imbalance cases of insertion?

A
  1. left-left case
  2. left-right case
  3. right-right case
  4. right-left case
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what are the 4 ways to rebalance an imbalance case of insertion?

A
  1. left-left: 2,1 case
    2: left-right: 2,-1 case
  2. right-right: -2,-1 case
  3. right-left, -2, 1 case
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

explain the 4 cases for rebalancing.

A
  1. 2,1: right rotation on root
  2. 2,-1: left rotation on internal node, then right rotation on root
  3. -2,-1: left rotation on root
    4: -2, 1: right rotation on internal node, then left rotation on root
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is the insertion algorithm?

A

BST insertion then all ancestors from parent to root are rebalanced, if any node has balance factor of 2 then rotation occurs

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

do all nodes have to be rebalanced after insertion? if no which nodes?

A

no, only nodes from parents up to root may need to be updated

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

what is the run time of insertion?

A

O(logn)

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

what is the run time of rotations

A

O(1)

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

what is the removal algorithm?

A

BST removal, all ancestors from parent node to root are rebalanced, if any node has a balance factor of 2 then rotation occurs

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

what is the run time of removal?

A

O(logn)