Write the three orders
Warm-up · Trace the algorithm · about 5 min
Look at the tree. For each traversal, drag the letters into the order the traversal visits them. Left children are always visited before right children.
Example 1
Input:
["pre-order"]
Output:
["A","B","D","E","C","F"]
Pre-order visits A first, then the whole left side.
Constraints
- The tree has 6 nodes, A to F
- Each order uses every node once
Learn the idea first: Pre-order, in-order, post-order, a visual lesson.
More Pre-order, in-order, post-order problems
- In-order of a search tree Warm-up
- Complete the in-order traversal Warm-up
- Pre-order traversal Standard
- Post-order traversal Standard
- In-order iteratively Standard
- Fix the post-order traversal Standard
- Build a tree from pre-order and in-order Challenge