The Hamiltonian Cycle Problem is NP-Completegasarch/COURSES/452/F14/hamtalk.pdfA Dialog 3...

46
The Hamiltonian Cycle Problem is NP-Complete Karthik Gopalan CMSC 452 November 25, 2014 Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 1 / 31

Transcript of The Hamiltonian Cycle Problem is NP-Completegasarch/COURSES/452/F14/hamtalk.pdfA Dialog 3...

  • The Hamiltonian Cycle Problem is NP-Complete

    Karthik Gopalan

    CMSC 452

    November 25, 2014

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 1 / 31

  • Outline

    Section 1

    Outline

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 2 / 31

  • Outline

    1 Introduction

    2 3-SAT ≤P Directed Ham PathProcedureConstructionExamplesA Dialog

    3 Hamiltonian Path ≤P Hamiltonian Cycle

    4 3-SAT ≤P Undirected Planar Hamiltonian CycleGadgetsConstruction

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 3 / 31

  • Introduction

    Section 2

    Introduction

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 4 / 31

  • Introduction

    What is a Hamiltonian Cycle

    A cycle through a graph G = (V ,E ) that touches every vertex once.

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 5 / 31

  • Introduction

    Hamiltonian Path ∈ NP

    1 The certificate: a path represented by an ordering of the verticies

    2 Verify:

    I Each node is in the path onceI An edge exists between each consecutive pair of nodes

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 6 / 31

  • Introduction

    Hamiltonian Path ∈ NP

    1 The certificate: a path represented by an ordering of the verticies2 Verify:

    I Each node is in the path onceI An edge exists between each consecutive pair of nodes

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 6 / 31

  • 3-SAT ≤P Directed Ham Path

    Section 3

    3-SAT ≤P Directed Ham Path

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 7 / 31

  • 3-SAT ≤P Directed Ham Path Procedure

    Subsection 1

    Procedure

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 8 / 31

  • 3-SAT ≤P Directed Ham Path Procedure

    Procedure

    1 Start with a 3-CNF formula

    φ = (a1 ∨ b1 ∨ c1) ∧ (a2 ∨ b2 ∨ c2) ∧ · · · ∧ (ak ∨ bk ∨ ck)

    2 Create a graph G that has a Hamiltonian Path iff φ is satisfiable

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 9 / 31

  • 3-SAT ≤P Directed Ham Path Procedure

    Procedure

    1 Start with a 3-CNF formula

    φ = (a1 ∨ b1 ∨ c1) ∧ (a2 ∨ b2 ∨ c2) ∧ · · · ∧ (ak ∨ bk ∨ ck)

    2 Create a graph G that has a Hamiltonian Path iff φ is satisfiable

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 9 / 31

  • 3-SAT ≤P Directed Ham Path Construction

    Subsection 2

    Construction

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 10 / 31

  • 3-SAT ≤P Directed Ham Path Construction

    Variables

    Represent each variable xi with a gadget with 3k + 3 nodes:

    xi . . .

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 11 / 31

  • 3-SAT ≤P Directed Ham Path Construction

    2 Ways

    True:

    xi . . .

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 12 / 31

  • 3-SAT ≤P Directed Ham Path Construction

    2 Ways

    False:

    xi . . .

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 12 / 31

  • 3-SAT ≤P Directed Ham Path Construction

    Clauses

    Each clause cj is represented as a single node:

    cj

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 13 / 31

  • 3-SAT ≤P Directed Ham Path Construction

    Connect the Variables

    x1

    s

    x2

    . . .

    . . .

    xn

    t

    c1

    c2

    c3

    c4

    ck

    ...

    . . .

    ...

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 14 / 31

  • 3-SAT ≤P Directed Ham Path Construction

    Connect the Clauses

    if xi ∈ Cjxi 3j. . . . . .

    cj

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 15 / 31

  • 3-SAT ≤P Directed Ham Path Construction

    Connect the Clauses

    if xi ∈ Cjxi 3j. . . . . .

    cj

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 15 / 31

  • 3-SAT ≤P Directed Ham Path Examples

    Subsection 3

    Examples

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 16 / 31

  • 3-SAT ≤P Directed Ham Path Examples

    (x ∨ y) ∧ (x ∨ y)

    y

    x

    C1 C2

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 17 / 31

  • 3-SAT ≤P Directed Ham Path Examples

    x ∧ x

    x

    C1 C2

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 18 / 31

  • 3-SAT ≤P Directed Ham Path A Dialog

    Subsection 4

    A Dialog

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 19 / 31

  • 3-SAT ≤P Directed Ham Path A Dialog

    At this point...

    Gasarch [to class]: So, could you code this up?

    Class: Yes!

    Gasarch: Would you want to?

    Class: No...

    Scott: Maybe in Prolog.

    Liz: If you paid me.

    Gasarch: What happened to the love of computer science! WhenClyde was an undergrad... The answer is 0 or on the board!... blahblah blah

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 20 / 31

  • 3-SAT ≤P Directed Ham Path A Dialog

    At this point...

    Gasarch [to class]: So, could you code this up?

    Class: Yes!

    Gasarch: Would you want to?

    Class: No...

    Scott: Maybe in Prolog.

    Liz: If you paid me.

    Gasarch: What happened to the love of computer science! WhenClyde was an undergrad... The answer is 0 or on the board!... blahblah blah

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 20 / 31

  • 3-SAT ≤P Directed Ham Path A Dialog

    At this point...

    Gasarch [to class]: So, could you code this up?

    Class: Yes!

    Gasarch: Would you want to?

    Class: No...

    Scott: Maybe in Prolog.

    Liz: If you paid me.

    Gasarch: What happened to the love of computer science! WhenClyde was an undergrad... The answer is 0 or on the board!... blahblah blah

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 20 / 31

  • 3-SAT ≤P Directed Ham Path A Dialog

    At this point...

    Gasarch [to class]: So, could you code this up?

    Class: Yes!

    Gasarch: Would you want to?

    Class: No...

    Scott: Maybe in Prolog.

    Liz: If you paid me.

    Gasarch: What happened to the love of computer science! WhenClyde was an undergrad... The answer is 0 or on the board!... blahblah blah

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 20 / 31

  • 3-SAT ≤P Directed Ham Path A Dialog

    At this point...

    Gasarch [to class]: So, could you code this up?

    Class: Yes!

    Gasarch: Would you want to?

    Class: No...

    Scott: Maybe in Prolog.

    Liz: If you paid me.

    Gasarch: What happened to the love of computer science! WhenClyde was an undergrad... The answer is 0 or on the board!... blahblah blah

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 20 / 31

  • 3-SAT ≤P Directed Ham Path A Dialog

    At this point...

    Gasarch [to class]: So, could you code this up?

    Class: Yes!

    Gasarch: Would you want to?

    Class: No...

    Scott: Maybe in Prolog.

    Liz: If you paid me.

    Gasarch: What happened to the love of computer science! WhenClyde was an undergrad... The answer is 0 or on the board!... blahblah blah

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 20 / 31

  • 3-SAT ≤P Directed Ham Path A Dialog

    At this point...

    Gasarch [to class]: So, could you code this up?

    Class: Yes!

    Gasarch: Would you want to?

    Class: No...

    Scott: Maybe in Prolog.

    Liz: If you paid me.

    Gasarch: What happened to the love of computer science! WhenClyde was an undergrad... The answer is 0 or on the board!... blahblah blah

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 20 / 31

  • Hamiltonian Path ≤P Hamiltonian Cycle

    Section 4

    Hamiltonian Path ≤P Hamiltonian Cycle

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 21 / 31

  • Hamiltonian Path ≤P Hamiltonian Cycle

    ...

    Question 4 on the Final

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 22 / 31

  • 3-SAT ≤P Undirected Planar Hamiltonian Cycle

    Section 5

    3-SAT ≤P Undirected Planar Hamiltonian Cycle

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 23 / 31

  • 3-SAT ≤P Undirected Planar Hamiltonian Cycle Gadgets

    Subsection 1

    Gadgets

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 24 / 31

  • 3-SAT ≤P Undirected Planar Hamiltonian Cycle Gadgets

    Or

    v v ′

    u u′

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 25 / 31

  • 3-SAT ≤P Undirected Planar Hamiltonian Cycle Gadgets

    Or

    v v ′

    u u′

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 25 / 31

  • 3-SAT ≤P Undirected Planar Hamiltonian Cycle Gadgets

    X-Or

    v v ′

    u u′

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 26 / 31

  • 3-SAT ≤P Undirected Planar Hamiltonian Cycle Gadgets

    X-Or

    v v ′

    u u′

    X

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 26 / 31

  • 3-SAT ≤P Undirected Planar Hamiltonian Cycle Construction

    Subsection 2

    Construction

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 27 / 31

  • 3-SAT ≤P Undirected Planar Hamiltonian Cycle Construction

    Variables

    xi

    xi

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 28 / 31

  • 3-SAT ≤P Undirected Planar Hamiltonian Cycle Construction

    Variables

    xi = false

    xi

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 28 / 31

  • 3-SAT ≤P Undirected Planar Hamiltonian Cycle Construction

    Variables

    xi = true

    xi

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 28 / 31

  • 3-SAT ≤P Undirected Planar Hamiltonian Cycle Construction

    Variables

    xi

    xi

    X

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 28 / 31

  • 3-SAT ≤P Undirected Planar Hamiltonian Cycle Construction

    Clauses

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 29 / 31

  • 3-SAT ≤P Undirected Planar Hamiltonian Cycle Construction

    (x ∨ y ∨ z) ∧ (x ∨ y ∨ w) ∧ (y ∨ z ∨ w)

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 30 / 31

  • 3-SAT ≤P Undirected Planar Hamiltonian Cycle Construction

    That’s BS Man!

    Karthik Gopalan (2014) The Hamiltonian Cycle Problem is NP-Complete November 25, 2014 31 / 31

    Introduction3-SAT P Directed Ham PathProcedureConstructionExamplesA Dialog

    Hamiltonian Path P Hamiltonian Cycle3-SAT P Undirected Planar Hamiltonian CycleGadgetsConstruction