Data Structures & AlgorithmsHardICPC regional · Codeforces Div2 D
Problem: In the undirected graph with edges 0-1, 0-2, 1-2, 1-3, 2-3, 3-4, how many simple paths (no repeated vertex) go from vertex 0 to vertex 4? Paths are counted as sequences of vertices.
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
Enumerate simple paths by DFS with a visited set; every route to vertex 4 ends at its only neighbour 3. Counting shortest paths only gives a smaller count.
More Coding Interview Problems questions
- Problem: An undirected forest (a graph with no cycles) has 9 vertices and 6 edges. How many connected components does it have?
- Problem: A rooted tree (root 1) has parent pointers: 2→1, 3→1, 4→2, 5→2, 6→4, 7→6, 8→3, 9→8. How many nodes lie on the path between node 7…
- Problem: For the complete binary tree with 10 nodes stored in heap order (node i has children 2i and 2i+1, root is node 1), what is the…
- Problem: Using the parent array par[i] for nodes 0–9 with par = [−1, 0, 0, 1, 1, 3, 3, 5, 6, 8], what is the 3rd ancestor of node 9 (the…
- Problem: Count the indices i of the string "abacaba" for which the suffix s[i:] is a palindrome.
- Problem: Deleting exactly one character from "aabca" produces some strings. How many distinct strings can result?