CS140-lecture-20211129

NP-completeness #

image_2021-11-29-16-42-42 image_2021-11-29-16-43-41 image_2021-11-29-16-44-31

Hamiltonian cycles #

An example of a problem that cannot be solved in polynomial time.

image_2021-11-29-16-46-19

P and NP #

image_2021-11-29-16-46-58 image_2021-11-29-16-47-13 image_2021-11-29-16-54-00 image_2021-11-29-16-55-51

Terminology #

image_2021-11-29-16-58-28

Reduction #

image_2021-11-29-17-05-54 image_2021-11-29-17-09-28 image_2021-11-29-17-10-47 image_2021-11-29-17-10-55 image_2021-11-29-17-13-26

  • should first show that \( P \in NP \)

NP-Hard #

image_2021-11-29-17-16-28

  • NP-Hard problems are at least as hard as NP-Complete problems

Why prove NP-completeness? #

image_2021-11-29-17-17-12 image_2021-12-01-16-00-07 image_2021-12-01-16-01-24

NP-Complete Examples #

image_2021-12-01-16-01-35

Reduction examples #

Directed hamiltonian cycle to undirected hamiltonian cycle #

It is easier to go the other way (for any undirected edge, we just make it directed in both directions).

So how do we turn a directed graph into an undirected graph, such that they both either have or have not a hamiltonian cycle?

For each vertex in the directed graph, put 3 vertices in the undirected graph:

image_2021-12-07-10-22-59

Then, for edges in the directed graph, put an edge from the third vertex to the first in the undirected graph:

image_2021-12-07-10-24-03 image_2021-12-07-10-24-52

Now, this particular example does not have a hamiltonian cycle, but lets pretend it does (with the darker color):

image_2021-12-07-10-26-12

Note that the undirected graph now has the entire perimeter filled in and we can see the hamiltonian cycle.

image_2021-12-07-10-29-37

The (bold) edges that go from a third vertice to a first vertice represent a hamiltonian cycle in the directed graph.

image_2021-12-07-10-31-58 image_2021-12-07-10-32-37

The traveling salesman problem #

image_2021-12-07-10-34-29

If we are trying to show that this problem is NP-Complete we need to:

  • show that the solution is verifiable in polynomial time
    • with the TSP solution, we can simply sum all of the edges

image_2021-12-07-10-37-36

We can reduce the Hamiltonian cycle problem to a TSP:

image_2021-12-07-10-37-50

If we reduce all edge weights to 1, and the TSP gives a result \( < n + 1 \) , then we have a hamiltonian cycle.