Q. How many rotations are needed in the worst case for balancing an AVL tree after an insertion?
Solution
In the worst case, 2 rotations may be needed to balance an AVL tree after an insertion.
Correct Answer:
B
— 2
Learn More →
Q. How many rotations are needed in the worst case to balance an AVL tree after an insertion?
Solution
In the worst case, 2 rotations may be needed to balance an AVL tree after an insertion.
Correct Answer:
B
— 2
Learn More →
Q. In a Red-Black tree, what color can the root node be?
-
A.
Red
-
B.
Black
-
C.
Either Red or Black
-
D.
None of the above
Solution
The root node of a Red-Black tree must always be black to maintain the properties of the tree.
Correct Answer:
B
— Black
Learn More →
Q. What is the balance factor of a node in an AVL tree?
-
A.
Height of left subtree - Height of right subtree
-
B.
Height of right subtree - Height of left subtree
-
C.
Number of nodes in left subtree - Number of nodes in right subtree
-
D.
Number of nodes in right subtree - Number of nodes in left subtree
Solution
The balance factor of a node in an AVL tree is calculated as the height of the left subtree minus the height of the right subtree.
Correct Answer:
A
— Height of left subtree - Height of right subtree
Learn More →
Q. What is the main advantage of using a Red-Black tree over an AVL tree?
-
A.
Faster search times
-
B.
Less strict balancing, leading to faster insertions and deletions
-
C.
Easier implementation
-
D.
More memory usage
Solution
Red-Black trees allow for less strict balancing compared to AVL trees, which can lead to faster insertions and deletions.
Correct Answer:
B
— Less strict balancing, leading to faster insertions and deletions
Learn More →
Q. What is the main property of an AVL tree?
-
A.
It is a binary search tree with a balance factor of -1, 0, or 1.
-
B.
It allows duplicate values.
-
C.
It is a complete binary tree.
-
D.
It is a binary tree with no children.
Solution
An AVL tree is a self-balancing binary search tree where the difference in heights between the left and right subtrees cannot be more than one.
Correct Answer:
A
— It is a binary search tree with a balance factor of -1, 0, or 1.
Learn More →
Q. What is the maximum height of an AVL tree with n nodes?
-
A.
O(log n)
-
B.
O(n)
-
C.
O(n log n)
-
D.
O(1)
Solution
The maximum height of an AVL tree is O(log n), which ensures efficient operations.
Correct Answer:
A
— O(log n)
Learn More →
Q. What is the time complexity for searching an element in an AVL tree?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
The time complexity for searching an element in an AVL tree is O(log n) due to its balanced nature.
Correct Answer:
B
— O(log n)
Learn More →
Q. Which of the following is NOT a property of a Red-Black tree?
-
A.
Every node is either red or black.
-
B.
The root is always red.
-
C.
Red nodes cannot have red children.
-
D.
Every path from a node to its descendant leaves must have the same number of black nodes.
Solution
The root of a Red-Black tree must always be black, not red.
Correct Answer:
B
— The root is always red.
Learn More →
Q. Which of the following operations can cause an imbalance in an AVL tree?
-
A.
Insertion
-
B.
Deletion
-
C.
Both Insertion and Deletion
-
D.
Traversal
Solution
Both insertion and deletion operations can cause an imbalance in an AVL tree, requiring rebalancing.
Correct Answer:
C
— Both Insertion and Deletion
Learn More →
Q. Which of the following operations is performed to maintain the balance of an AVL tree?
-
A.
Insertion
-
B.
Deletion
-
C.
Rotation
-
D.
Traversal
Solution
Rotations (single or double) are performed to maintain the balance of an AVL tree after insertions or deletions.
Correct Answer:
C
— Rotation
Learn More →
Showing 1 to 11 of 11 (1 Pages)