Data Structures · Assignment · Problem 2

Problem 2: Reconstruct the Binary Tree

Pre-order: A B D E C F · In-order: D B E A F C → reconstruct the tree and find the post-order

🌳 The reconstructed binary tree

Pre-order
In-order
node reconstructed the root picked from pre in this step / being processed just created / already printed by post-order ROOT LEAF top two rows: yellow = current recursive range, blue = the root picked in this step

💬 Current step

💻 Lecture C++ code (whole program)

Yellow = current line. ① build(): the first element of pre is the root; split in around it and recurse. ② post-order traversal as a check.

🥞 Recursion call stack build(pre part / in part) · postorder

Speed
Shortcuts: Space play/pause · ←→ step · R reset · E result