Q. How do you perform a left rotation on a node in an AVL tree?
-
A.
Make the right child the new root of the subtree
-
B.
Make the left child the new root of the subtree
-
C.
Swap the node with its parent
-
D.
No rotation is needed
Solution
A left rotation involves making the right child the new root of the subtree and adjusting the left child accordingly.
Correct Answer:
A
— Make the right child the new root of the subtree
Learn More →
Q. In a Red-Black Tree, what must be true about the path from any node to its descendant leaves?
-
A.
All paths must have the same number of black nodes
-
B.
All paths must have the same number of red nodes
-
C.
All paths must alternate colors
-
D.
All paths must have at least one red node
Solution
In a Red-Black Tree, every path from a node to its descendant leaves must have the same number of black nodes.
Correct Answer:
A
— All paths must have the same number of black nodes
Learn More →
Q. In an AVL tree, what operation is performed when a node becomes unbalanced after an insertion?
-
A.
Rotation
-
B.
Traversal
-
C.
Deletion
-
D.
Rebalancing
Solution
When a node becomes unbalanced after an insertion, a rotation (single or double) is performed to restore balance.
Correct Answer:
A
— Rotation
Learn More →
Q. What is the main property that distinguishes an AVL tree from a regular binary search tree?
-
A.
It is always balanced with a height difference of at most 1
-
B.
It allows duplicate values
-
C.
It can have any height difference
-
D.
It is implemented using linked lists
Solution
An AVL tree maintains a balance factor of -1, 0, or 1 for every node, ensuring that the tree remains balanced.
Correct Answer:
A
— It is always balanced with a height difference of at most 1
Learn More →
Q. What is the primary reason for using AVL trees over regular binary search trees?
-
A.
Easier implementation
-
B.
Faster search times
-
C.
Better memory usage
-
D.
More balanced structure
Solution
AVL trees maintain a more balanced structure than regular binary search trees, leading to better performance in search operations.
Correct Answer:
D
— More balanced structure
Learn More →
Q. What is the time complexity of inserting an element into a Red-Black tree?
-
A.
O(log n)
-
B.
O(n)
-
C.
O(n log n)
-
D.
O(1)
Solution
The time complexity of inserting an element into a Red-Black tree is O(log n) due to its balanced nature.
Correct Answer:
A
— O(log n)
Learn More →
Q. What is the time complexity of searching for an element in a balanced AVL tree?
-
A.
O(log n)
-
B.
O(n)
-
C.
O(n log n)
-
D.
O(1)
Solution
The time complexity of searching in an AVL tree is O(log n) due to its balanced nature.
Correct Answer:
A
— O(log n)
Learn More →
Q. Which of the following properties is true for a Red-Black Tree?
-
A.
Every node is either red or black
-
B.
The root is always red
-
C.
All leaves are red
-
D.
Red nodes can have red children
Solution
In a Red-Black Tree, every node is either red or black, and there are specific properties that maintain balance.
Correct Answer:
A
— Every node is either red or black
Learn More →
Showing 1 to 8 of 8 (1 Pages)