Skip to content
GATEiit

GATE CSE 2018 Q30: Height of binary tree from postorder and inorder traversals

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

Numerical answer. No negative marking.
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.

Concept notes

Loading notes…

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

WhatsAppDownload image

Source: official GATE 2018 CS question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key