Data Structures & AlgorithmsVery hardICPC regional · graph theory
Problem: Which claim about the complexity of deciding 2-SAT (satisfiability of clauses with at most two literals) is correct?
- A. It is solvable in linear time O(n + m) via strongly connected components of the implication graph
- B. It is NP-complete, so no polynomial algorithm is known
- C. It needs exponential time in the number of variables
- D. It is solvable only with dynamic programming over all 2^n assignments
Correct answer: A. It is solvable in linear time O(n + m) via strongly connected components of the implication graph
Each clause a OR b gives implications not a -> b and not b -> a, and the formula is satisfiable exactly when no variable shares an SCC with its negation. 3-SAT, not 2-SAT, is NP-complete.
More Coding Interview Problems questions
- Problem: Which of the following problems is NP-complete (decision version)?
- Problem: For Dijkstra on a graph with V vertices and E edges, which pairing of data structure and running time is correct?
- Problem: For a set of 40 items split into two halves of 20, the meet-in-the-middle approach solves subset-sum queries in roughly which time?
- Problem: Grundy numbers for the subtraction game where a move removes 1 or 2 stones: what are g(0) through g(5)? Run the code. python g =…
- Problem: Using the bubble sort rule, what is the array after exactly one left-to-right pass over [3, 1, 2]? Run the code. python a = [3…
- Problem: How many legal moves does a knight have from the corner (0,0) of an 8 x 8 board? Run the code. python moves = [(1, 2), (2, 1)…