Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D
Problem: Vertices 1–5 of a directed graph have arcs 1→2, 2→3, 3→1, 3→4, 4→5, 5→4, and 1→5. Using DFS from vertex 1, how many back edges (edges to an ancestor on the current DFS stack) are found? Visit neighbours in increasing order.
- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: B. 2
In a DFS of a directed graph, a back edge is one that points to a vertex still on the recursion stack. Edges into finished vertices are forward or cross edges and are not counted.
More Coding Interview Problems questions
- Problem: A tree with 6 nodes is given by parent array p = [−1, 0, 0, 2, 2, 4] for nodes 0–5 (root 0). What is the number of nodes whose…
- Problem: The string "xyzzyxzz" is considered. How many of its substrings of length 3 are palindromes (counted by index)?
- Problem: Among the strings "abc", "bca", "cab", "acb", "bac", "cba", how many distinct pairs (x, y) with x ≠ y are rotations of each other…
- Problem: Find the length of the longest substring of "aaabbbbcccd" that contains at most two distinct letters.
- Problem: How many numbers from 1 to 1000 have a digit sum divisible by 9?
- Problem: How many ways are there to write 20 as an ordered sum of parts from {2, 3, 5}?