Data Structures & AlgorithmsModerateICPC regional · complexity theory
Problem: Which of the following problems is NP-complete (decision version)?
- A. Does a graph contain an Euler circuit?
- B. Does a graph contain a Hamiltonian cycle?
- C. Is there a path of length at most k between two vertices?
- D. Is a given array sorted?
Correct answer: B. Does a graph contain a Hamiltonian cycle?
Hamiltonian cycle is one of Karp's 21 NP-complete problems. Euler circuits are decidable in linear time by checking degrees and connectivity, and the other two are polynomial.
More Coding Interview Problems questions
- 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)…
- Problem: What is 7^222 mod 10? Run the code. python print(pow(7, 222, 10)) What is printed?