← Student tools · Problem 24 · Lecture 10 · Round 2 (30 pts)

Classic P problems · PATH, RELPRIME, ACFG

Three poly-time algorithms with explicit running times.

CLO-3R2·30 ptsL10
🔊 Listen

P = ⋃k TIME(nk) — the union over all k of "decidable in O(nk) time." Sipser's three flagship examples (§7.2) cover the three flavors of "polynomial":

PATH = {⟨G, s, t⟩ : G has a directed path from s to t}

Algorithm: BFS from s; mark every reachable vertex. Accept iff t is marked.

Time: O(V + E). Linear in the graph size — about as fast as polynomial gets.

RELPRIME = {⟨a, b⟩ : gcd(a, b) = 1}

Algorithm: Euclid's algorithm — repeatedly replace (a, b) with (b, a mod b) until b = 0; gcd is the final a.

Time: O(log min(a, b)) iterations. Polynomial in bit length, which is what matters.

ACFG = {⟨G, w⟩ : CFG G generates w}

Algorithm: convert G to CNF; run CYK dynamic programming.

Time: O(n³ · |G|). Cubic — slower than the others but still polynomial.

🔊 Listen
In P (left) vs apparently-not-in-P (right) · a structural change shifts everything In P PATH (any s-t path) RELPRIME (gcd = 1) ADFA (DFA accepts w) ACFG (CFG generates w) EDFA (DFA empty?) EQDFA (DFAs equivalent?) All have explicit polynomial algorithms. Probably not in P HAMPATH (visit ALL vertices) SUBSET-SUM (cardinality choice) SAT (boolean satisfiability) CLIQUE (size-k clique exists?) 3-COLOR (graph 3-colorable?) EQCFG (CFGs equivalent?) All NP-complete or worse.

The shift is often a single quantifier or a "for all/exists every" change. PATH asks any s-t path — easy. HAMPATH asks a path visiting every vertex — combinatorially hard. ADFA simulates one machine — easy. SAT asks for an assignment that satisfies every clause — hard.

🔊 Listen
Cycle through three classic P problems Auto-plays
🔊 Listen
🔊 Listen
🔊 Listen

Sipser: §7.2 (the three classic examples), Theorem 7.14, 7.15, 7.16. Lecture notes: Module 4 slide 5. Companion problems: P12 (decidable trio), P17 (growth race), P48 (P vs EXPTIME).