Data Structures & AlgorithmsVery hardCodeforces Div2 B · ICPC regional

A rooted tree has these parent→child edges: 93→2, 86→35, 75→63, 40→26, 7→42, 42→40, 86→60, 63→92, 2→7, 26→75, 93→95, 40→86. A depth-first search starts at the root and, at every node, visits its children in increasing order of label. Give the postorder (a node is printed only after every node of its subtree) as a sequence of node labels.

  1. A. 95 60 35 86 92 63 75 26 40 42 7 2 93
  2. B. 93 2 7 42 40 26 75 63 92 86 35 60 95
  3. C. 92 63 75 26 35 60 86 40 42 7 2 95 93
  4. D. 93 2 95 7 42 40 26 86 75 35 60 63 92

Correct answer: C. 92 63 75 26 35 60 86 40 42 7 2 95 93

Postorder is decided by where a node is printed relative to its subtree; with children in increasing label order the sequence is 92 63 75 26 35 60 86 40 42 7 2 95 93. Reversing the child order or swapping the two traversals are the usual slips.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic