Data Structures & AlgorithmsHardICPC regional · Codeforces Div2 D
Problem: A directed graph has vertices 0–3 with arcs 0→1, 1→2, 2→1, 2→3. Using DFS from vertex 0 with children visited in increasing order, which vertex is the first to be finished (post-order first)?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
The first vertex to finish is the deepest one reached first: 3 has no outgoing arcs, so it finishes before 2 and the rest of the recursion.
More Coding Interview Problems questions
- Problem: Tree with root 1 and children 1: [2, 3], 2: [4, 5], 4: [6]. What is the number of nodes in the subtree of node 2 (node 2 counts…
- Problem: The string "abracadabra" contains the substring "abra" at several positions. How many occurrences of "abra" are there (overlaps…
- Problem: The string "abcdefghij" is split into blocks of length 4 from the left (the last block may be shorter). How many blocks have…
- Problem: The number of permutations of the digits 1, 2, 3, 4 in which the digit 1 is not in the first position and 4 is not in the last…
- Problem: Cars pass a toll booth at times 2, 5, 6, 10, 11, 15 (minutes). A car may pass only if at least 3 minutes have elapsed since the…
- Problem: A sorted list of distinct integers is 3, 8, 12, 17, 21, 26, 30. How many pairs (i < j) have a[j] − a[i] exactly equal to 9?