GATE CSE 2018 Q30: Height of binary tree from postorder and inorder traversals
- Programming and Data Structures
- 1 mark
- NAT
- No negative marking
Syllabus topic: Trees, binary search trees and binary heaps
Question
The postorder traversal of a binary tree is 8,9,6,7,4,5,2,3,1. The inorder traversal of the same tree is 8,6,9,4,7,2,5,1,3. The height of a tree is the length of the longest path from the root to any leaf. The height of the binary tree above is ______.
Try it: numerical answer: type the value
Show answer and explanation
Answer: 4 (official GATE 2018 final answer key)
Concept used: The last element of a postorder traversal is the root; its position in the inorder traversal splits the left and right subtrees, recursively.
First step: Take 1 (last in postorder) as the root, split the inorder list around it, and repeat for each subtree to rebuild the tree; then count edges on the longest root-to-leaf path.
Full step-by-step solution
Loading…
Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.
More questions on Trees, binary search trees and binary heaps
Every PYQ on this topic →Share this question
Source: official GATE 2018 CS question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key
More Programming and Data Structures PYQs
- 2026 Session 1 · Q23Non-leaf indices in a 1-indexed binary heap with n odd
- 2026 Session 1 · Q24Empty slots after linear-probing inserts with h(x) = (x+7) mod 11
- 2026 Session 1 · Q33Maximum height of a full binary tree with 23 nodes
- 2026 Session 1 · Q34Output of a C function with a shadowed block variable
- 2026 Session 1 · Q39Recursive length of a non-empty singly linked list
- 2026 Session 1 · Q40Third insertion that can never yield a complete BST of 1..15