Skip to content
Related Articles

Related Articles

Improve Article

GATE | GATE CS 2008 | Question 46

  • Difficulty Level : Hard
  • Last Updated : 28 Jun, 2021

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?
(A) O(Logn)
(B) O(n)
(C) O(nLogn)
(D) none of the above, as the tree cannot be uniquely determined.


Answer: (B)

Explanation: One important thing to note is, it is Binary Search Tree, not Binary Tree. In BST, inorder traversal can always be obtained by sorting all keys.

See method 2 of https://www.geeksforgeeks.org/construct-bst-from-given-preorder-traversa/ for details.

Same technique can be used for postorder traversal.

Quiz of this Question

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :