Exams › GATE › Technical
You are given the postorder traversal, P, of a binary search tree on the n elements 1, 2,..., n. You have to determine the unique binary search tree that has P as its postorder traversal. What is the time complexity of the most efficient algorithm for doing this?
- Θ(log n)
- Θ(n)
- Θ(n log n)
- none of the above, as the tree cannot be uniquely determined.
Correct answer: Θ(n)
Solution
The correct option is Θ(n) because reconstructing a binary search tree from its postorder traversal involves processing each of the n elements exactly once to determine their positions in the tree, leading to a linear time complexity.
Related GATE Technical questions
⚔️ Practice GATE Technical free + battle 1v1 →