Data Structures & AlgorithmsVery hardCodeforces Div2 B · ICPC regional

A rooted tree has these parent→child edges: 33→90, 60→16, 19→45, 46→80, 46→19, 80→92, 45→60, 92→37, 60→14, 33→48, 33→69, 80→33. A depth-first search starts at the root and, at every node, visits its children in increasing order of label. Give the preorder (a node is printed before every node of its subtree) as a sequence of node labels.

  1. A. 46 80 92 37 33 90 69 48 19 45 60 16 14
  2. B. 14 16 60 45 19 48 69 90 33 37 92 80 46
  3. C. 46 19 45 60 14 16 80 33 48 69 90 92 37
  4. D. 46 19 80 45 33 92 60 48 69 90 37 14 16

Correct answer: C. 46 19 45 60 14 16 80 33 48 69 90 92 37

Preorder is decided by where a node is printed relative to its subtree; with children in increasing label order the sequence is 46 19 45 60 14 16 80 33 48 69 90 92 37. 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