AlgoFrames

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