Data Structures & AlgorithmsHardCodeforces Div2 B · ICPC regional
A rooted tree has these parent→child edges: 95→93, 88→72, 93→20, 37→88, 37→95, 20→31, 66→37. 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.
- A. 31 20 93 95 72 88 37 66
- B. 66 37 88 72 95 93 20 31
- C. 72 88 31 20 93 95 37 66
- D. 66 37 88 95 72 93 20 31
Correct answer: C. 72 88 31 20 93 95 37 66
Postorder is decided by where a node is printed relative to its subtree; with children in increasing label order the sequence is 72 88 31 20 93 95 37 66. Reversing the child order or swapping the two traversals are the usual slips.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A rooted tree has these parent→child edges: 20→69, 75→47, 60→40, 60→20, 47→96, 74→32, 74→75, 74→60, 20→46, 47→36. A depth-first search…
- A rooted tree has these parent→child edges: 15→97, 97→40, 48→32, 15→43, 15→70, 48→15, 36→90, 36→16, 32→36, 70→96. A depth-first search…
- A rooted tree has these parent→child edges: 16→95, 70→51, 16→37, 16→83, 51→23, 51→86, 95→70, 86→85, 70→45, 37→58, 3→62, 58→32, 3→16. A…
- 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…
- A rooted tree has these parent→child edges: 32→83, 28→84, 28→26, 28→91, 26→25, 37→34, 11→27, 7→37, 27→28, 32→47, 11→32, 32→75, 84→7. A…
- A rooted tree has these parent→child edges: 60→16, 16→15, 9→58, 44→17, 17→87, 58→40, 98→60, 15→44, 60→69, 58→98. A depth-first search…