What is the main difference between Inorder and Postorder traversal?
Inorder visits nodes in Left, Root, Right order, while Postorder visits nodes in Left, Right, Root order.
Click to reveal answer
In Postorder traversal, which node is visited last?
ARight child
BLeft child
CRoot node
DNone of the above
✗ Incorrect
Postorder visits Left subtree, then Right subtree, and finally the Root node.
What is the Postorder traversal of a tree with root 5, left child 3, and right child 7?
A3 -> 7 -> 5
B3 -> 5 -> 7
C7 -> 3 -> 5
D5 -> 3 -> 7
✗ Incorrect
Postorder visits Left (3), Right (7), then Root (5).
Which traversal is best suited for deleting all nodes in a tree safely?
APreorder
BPostorder
CInorder
DLevel order
✗ Incorrect
Postorder visits children before the parent, so it deletes safely.
In Postorder traversal, what is the first subtree visited?
ALeft subtree
BRoot node
CRight subtree
DNone
✗ Incorrect
Postorder starts with the Left subtree.
Which of these is the correct Postorder traversal output for this tree? Root: 10 Left child: 5 Right child: 15
A5 -> 10 -> 15
B10 -> 5 -> 15
C15 -> 10 -> 5
D5 -> 15 -> 10
✗ Incorrect
Postorder visits Left (5), Right (15), then Root (10).
Explain the steps of Postorder traversal on a binary tree.
Think about visiting children before the parent.
You got /4 concepts.
Describe a real-life scenario where Postorder traversal is useful.
Consider tasks that require finishing all parts before the whole.
You got /3 concepts.
Practice
(1/5)
1. What is the order of nodes visited in a postorder tree traversal?
easy
A. Root node, Right subtree, Left subtree
B. Root node, Left subtree, Right subtree
C. Left subtree, Right subtree, Root node
D. Right subtree, Left subtree, Root node
Solution
Step 1: Understand postorder traversal definition
Postorder traversal visits the left subtree first, then the right subtree, and finally the root node.
Step 2: Match the order with options
Left subtree, Right subtree, Root node matches the order Left, Right, Root exactly.
Final Answer:
Left subtree, Right subtree, Root node -> Option C
Quick Check:
Postorder = Left, Right, Root [OK]
Hint: Remember postorder ends with root after children [OK]
Common Mistakes:
Confusing postorder with preorder or inorder
Visiting root before children
Swapping left and right subtree order
2. Which of the following Go function signatures correctly represents a recursive postorder traversal of a binary tree node root?
easy
A. func postorder(root *Node) { postorder(root.Left); postorder(root.Right); fmt.Println(root.Value) }
B. func postorder(root *Node) { fmt.Println(root.Value); postorder(root.Left); postorder(root.Right) }
C. func postorder(root *Node) { postorder(root.Right); postorder(root.Left); fmt.Println(root.Value) }
D. func postorder(root *Node) { fmt.Println(root.Value); postorder(root.Right); postorder(root.Left) }
Solution
Step 1: Recall postorder traversal steps
Postorder visits left subtree, then right subtree, then root node.
Step 2: Check function calls and print order
func postorder(root *Node) { postorder(root.Left); postorder(root.Right); fmt.Println(root.Value) } calls postorder on left, then right, then prints root value, matching postorder.
A. The order of recursive calls is swapped; left should be before right
B. The base case is missing for nil nodes
C. The root value should be printed before recursive calls
D. The function should return a slice instead of printing
Solution
Step 1: Analyze recursive call order
The code calls postorder on right subtree first, then left subtree, which reverses the expected order.
Step 2: Recall correct postorder sequence
Postorder requires left subtree first, then right subtree, then root. Swapping left and right causes wrong output.
Final Answer:
The order of recursive calls is swapped; left should be before right -> Option A
Quick Check:
Left before Right in postorder [OK]
Hint: Left subtree call must come before right subtree call [OK]
Common Mistakes:
Swapping left and right subtree calls
Printing root before children
Ignoring base case for nil
5. You want to collect the values of a binary tree in postorder traversal into a slice instead of printing. Which Go function correctly implements this?
hard
A. func postorder(root *Node, res *[]int) {
if root == nil {
return
}
postorder(root.Right, res)
postorder(root.Left, res)
*res = append(*res, root.Value)
}
B. func postorder(root *Node) []int {
if root == nil {
return []int{}
}
left := postorder(root.Left)
right := postorder(root.Right)
return append(left, append(right, root.Value)...)
}
C. func postorder(root *Node, res *[]int) {
if root == nil {
return
}
*res = append(*res, root.Value)
postorder(root.Left, res)
postorder(root.Right, res)
}
D. func postorder(root *Node) []int {
if root == nil {
return nil
}
return []int{root.Value}
}
Solution
Step 1: Understand collecting values in slice recursively
We want a function returning a slice with postorder values: left subtree slice + right subtree slice + root value.
Step 2: Check each option for correct order and slice handling
func postorder(root *Node) []int {
if root == nil {
return []int{}
}
left := postorder(root.Left)
right := postorder(root.Right)
return append(left, append(right, root.Value)...)
} correctly returns left slice, then appends right slice, then root value, matching postorder traversal.
Final Answer:
func postorder(root *Node) []int {
if root == nil {
return []int{}
}
left := postorder(root.Left)
right := postorder(root.Right)
return append(left, append(right, root.Value)...)
} -> Option B
Quick Check:
Return slices: left + right + root [OK]
Hint: Return left + right + root slices combined [OK]
Common Mistakes:
Appending root before children slices
Not combining slices correctly
Returning nil instead of empty slice for nil node
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.