Test Flashcards

(22 cards)

1
Q

What is the purpose of rotations in an AVL tree?

A

To maintain height balance after inserting an item.

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

What does a rotation in a BST maintain?

A

The BST ordering property.

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

What is a simple right rotation?

A

A local rearrangement that balances an unbalanced AVL tree.

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

In an AVL tree, what does a balance factor of 2 indicate?

A

The tree is unbalanced and needs a rotation.

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

Which node becomes the new root after a right rotation at node 86?

A

Node 75.

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

What happens to node 86 after a right rotation at node 86?

A

It becomes the right child of node 75.

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

In a right rotation, what does B’s former right child C become?

A

D’s left child.

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

What is the initial state of an AVL tree that requires a left rotation?

A

An unbalanced tree with a balance factor of -2.

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

What does the AVLTreeUpdateHeight algorithm do?

A

Updates a node’s height value based on its child subtree heights.

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

What is the precondition for the AVLTreeGetBalance function?

A

The node argument must be non-null.

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

True or False: AVLTreeGetBalance() has a precondition that the node’s children are both non-null.

A

False.

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

What does the AVLTreeSetChild algorithm do?

A

Sets a node as the parent’s left or right child and updates the child’s parent pointer.

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

What is a right rotation algorithm defined on?

A

A subtree root (node D) that must have a left child (node B).

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

What is the role of AVLTreeRotateRight function?

A

Performs a right rotation on a specified node in an AVL tree.

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

What is the result of a right rotation at node D?

A

Node B becomes the new root of the subtree.

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

What should be done if an AVL tree node has a balance factor of 2 or -2?

A

Rebalance the node via rotations.

17
Q

True or False: AVLTreeRebalance rebalances all ancestors from the node up to the root.

18
Q

What is the effect of AVLTreeRebalance if a node’s balance factor is 1, 0, or -1?

A

It takes no action.

19
Q

What does the AVLTreeRebalance algorithm do if the balance factor is -2?

A

It may perform a double rotation case and then a left rotation.

20
Q

What is the outcome of a left rotation at a node?

A

It is the symmetrical operation to a right rotation.

21
Q

Fill in the blank: In a right rotation, the left child of node D becomes the new ______.

22
Q

What happens to the balance factors of all nodes after a successful rotation?

A

They are updated to reflect the new structure.