Construct Binary Tree from Inorder and Postorder
Root pick from postorder + inorder range partitioning (right first)
Python Code
7 nonlocal post_ptr8 if left > right:9 return None10 ● root_val = postorder[post_ptr]12 post_ptr -= 1......15 16 root.right = build(mid + 1, right)17 root.left = build(left, mid - 1)18 return root19 Current Line (11): Pick root from postorder
Tree Structure
Operation:Pick Root
Build Progress
Build Stack
Stack is empty. Click Next to begin!
Step Explanation
Line 11: pick_root
Pick 3 from postorder and split inorder at index 1
- > Meaning: Current postorder pointer gives the root value.
- > Why: Postorder ends with Root, so scanning backward yields root first.
- > Next: Create root and split inorder range.
- > Progress snapshot: 0/26 steps, 0 nodes created.
Unvisited
Left
Current
Right
Done