AVL Tree · Data Structures
7 questions · asked in 6 of 27 years (2000–2026)
MCQ 6 · NAT 11-mark 4 · 2-mark 3
2000Questions per year2026
Questions 1–5 of 7
What is the worst case time complexity of inserting elements into an AVL-tree with n elements initially?
Answer: (C)
One AVL insertion takes time, with the size of the tree at that moment. The tree starts with elements and ends with , so always .
Upper bound: .
Lower bound: a tree with nodes has height at least about , and a worst-case insertion goes down to a deepest level, so it costs .
So each insertion costs in the worst case.
For insertions the total is .
Answer: (C)
Upper bound: .
Lower bound: a tree with nodes has height at least about , and a worst-case insertion goes down to a deepest level, so it costs .
So each insertion costs in the worst case.
For insertions the total is .
Answer: (C)
In a balanced binary search tree with n elements, what is the worst case time complexity of reporting all elements in range [a,b]? Assume that the number of reported elements is k.
Answer: (B)
Find a in time, since that is the tree height. Then walk the tree in order and report elements until b is passed. The walk touches the k reported elements and boundary nodes.
Total time:
Answer:
Total time:
Answer:
Suppose we have a balanced binary search tree T holding n numbers. We are given two numbers L and H and wish to sum up all the numbers in T that lie between L and H. Suppose there are m such numbers in T. If the tightest upper bound on the time to compute the sum is , the value of a + 10b + 100c + 1000d is _______.
Answer: 110
Search for L in the balanced BST. This takes . Then do an in-order walk over the m values up to H. This takes O(m).
Total time = a = 0, b = 1, c = 1, d = 0
a + 10b + 100c + 1000d = 0 + 10 + 100 + 0 = 110
Answer: 110
Total time = a = 0, b = 1, c = 1, d = 0
a + 10b + 100c + 1000d = 0 + 10 + 100 + 0 = 110
Answer: 110
The worst case running time to search for an element in a balanced binary search tree with elements is
Answer: (C)
A search in a balanced BST needs time, where .
Simplify the log:
Answer:
Simplify the log:
Answer:
What is the maximum height of any AVL-tree with 7 nodes? Assume that the height of a tree with a single node is 0.
Answer: (B)
A tree with node has a height of .
The height is largest when every level holds the fewest nodes possible.
Let be the fewest nodes in an AVL tree of height . The root has one subtree of height and one of height at the least, so:
Base values: , .
Then:
With nodes, height is possible because . Height would need at least nodes, and . So the maximum height is .
Answer: (B)
Keep practising