Q. How many rotations are required in the worst case when inserting a node in an AVL tree?
Solution
In the worst case, only 1 or 2 rotations are required to maintain the balance of an AVL tree after insertion.
Correct Answer:
B
— 2
Learn More →
Q. What is the primary purpose of balancing in AVL and Red-Black trees?
-
A.
To reduce memory usage
-
B.
To ensure O(log n) time complexity for operations
-
C.
To simplify the tree structure
-
D.
To allow duplicate values
Solution
The primary purpose of balancing in AVL and Red-Black trees is to ensure O(log n) time complexity for operations.
Correct Answer:
B
— To ensure O(log n) time complexity for operations
Learn More →
Q. What is the time complexity of deleting a node in a Red-Black tree?
-
A.
O(log n)
-
B.
O(n)
-
C.
O(n log n)
-
D.
O(1)
Solution
The time complexity of deleting a node in a Red-Black tree is O(log n) due to the balancing operations.
Correct Answer:
A
— O(log n)
Learn More →
Q. Which of the following is a valid property of AVL trees?
-
A.
The height difference between left and right subtrees can be at most 2.
-
B.
Every node must be black.
-
C.
The height difference between left and right subtrees can be at most 1.
-
D.
All leaves are red.
Solution
In AVL trees, the height difference between left and right subtrees can be at most 1.
Correct Answer:
C
— The height difference between left and right subtrees can be at most 1.
Learn More →
Q. Which of the following operations is NOT performed during the insertion in a Red-Black tree?
-
A.
Coloring the nodes
-
B.
Rotations
-
C.
Rebalancing
-
D.
Sorting the nodes
Solution
Sorting the nodes is not an operation performed during the insertion in a Red-Black tree.
Correct Answer:
D
— Sorting the nodes
Learn More →
Showing 1 to 5 of 5 (1 Pages)