Data Structures & AlgorithmsHardCodeforces Div2 B · ICPC regional

A rooted tree has these parent→child edges: 33→61, 68→22, 40→11, 61→87, 34→68, 61→35, 22→33, 34→83, 34→40. 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. 83 87 35 61 33 22 68 11 40 34
  2. B. 34 40 11 68 22 33 61 35 87 83
  3. C. 34 40 68 83 11 22 33 61 35 87
  4. D. 11 40 35 87 61 33 22 68 83 34

Correct answer: D. 11 40 35 87 61 33 22 68 83 34

Postorder is decided by where a node is printed relative to its subtree; with children in increasing label order the sequence is 11 40 35 87 61 33 22 68 83 34. 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