GATE / CS ARCHIVE

GATE CSE 2013 / QUESTION 18

Cycle detection and complexity classes

Algorithms · Computational Complexity · Full GATE CSE 2013 paper

GATE 2013, Q18 1 mark · MCQ
Not in GATE 2027 syllabusReport issue

Computational Complexity

Question 18, GATE 2013: Which are true?1 Undirected-cycle detection is in P.2 It is in NP.3 Every NP-complete problem has a nondeterministic polynomial-time algorithm. A1, 2, 3; B1, 2; C2, 3; D1, 3.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Undirected-cycle detection is polynomial via DFS or union-find, so it belongs to P and therefore also NP. By definition an NP-complete decision problem belongs to NP and has a nondeterministic polynomial-time algorithm. All three statements are true, A.

DFS detects an undirected cycle in O(V+E) time by finding an already visited neighbor other than the parent, so the first claim is polynomial. Every deterministic polynomial computation is also an allowed nondeterministic polynomial computation, giving P⊆NP and claim 2. NP-completeness includes membership in NP in its definition, not only NP-hardness, so claim 3 follows. No assumption that P≠NP is needed for any of these conclusions.

Original paper, page 4 · Answer key