Model answer
Preorder is node-left-right, inorder left-node-right, and postorder left-right-node; recursion or an explicit stack implements each. Level order visits breadth-first with a queue.
Use the key terms, then explain the reasoning.
Preorder, inorder, postorder, and level order visit every node in different orders for different tasks.
Open this in the visual labDepth-first traversals differ only in when the node is processed relative to its recursive subtrees: preorder before both, inorder between them, and postorder after both. The recursive structure directly mirrors the tree definition.
Level order is breadth-first and uses a queue. Iterative DFS replaces recursion with an explicit stack, which makes state and memory limits visible and permits custom traversal control.
Traverse a seven-node perfect tree
| Operation | Best | Average | Worst | Extra space |
|---|---|---|---|---|
| Traversal | O(n) | O(n) | O(n) | O(h) |
Each traversal visits every node once; the order changes the meaning of the output.
Open a prompt when you are ready to check your answer.