preparation capes - difficult problems on graphs (notions ......np - completeness np-complete...

36
Preparation CAPES Difficult problems on graphs (notions of) NP completeness Laure Gonnord Université Claude Bernard Lyon1 2017

Upload: others

Post on 03-Oct-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

Preparation CAPESDifficult problems on graphs

(notions of) NP completeness

Laure Gonnordhttp://laure.gonnord.org/pro/teaching/

[email protected]

Université Claude Bernard Lyon1

2017

Page 2: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

Difficult problems on graphs, NP-completeness

Laure Gonnord (UCB Lyon1) Graphs 2017 � 2 / 36 �

Page 3: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

1 More difficult problems on graphs

2 NP - completeness

3 Docs

Laure Gonnord (UCB Lyon1) Graphs 2017 � 3 / 36 �

Page 4: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

Eulerian and Hamiltonian paths

Eulerian/Hamiltonian PathAn Eulerian path : each edge is seen only once.An Hamiltonien path : each node ...

Laure Gonnord (UCB Lyon1) Graphs 2017 � 4 / 36 �

Page 5: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

Hamiltonian Tour, one solution

Extend a path until not possibleBacktrack one time, and try with another neighbourAnd so on.

I Worst case complexity time : exponential in n

Laure Gonnord (UCB Lyon1) Graphs 2017 � 5 / 36 �

Page 6: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

Application 1 : Knight’s Tour

Is it possible to make a Knight’s tour ? « The knight is placed onthe empty board and, moving according to the rules of chess,must visit each square exactly once.»I A variant of the Hamiltonian tour that can be solved inpolynomial time.

Laure Gonnord (UCB Lyon1) Graphs 2017 � 6 / 36 �

Page 7: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

The Travelling Salesman Problem

with valuated (non oriented) graph.I Find an hamiltonian cycle of minimum weight

Laure Gonnord (UCB Lyon1) Graphs 2017 � 7 / 36 �

Page 8: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

Travelling Salesman Problem - 2

A (non-polynomial) algorithm for this problem :Transform into a linear programming problem with integersSolve it with the simplex !

I This algorithm is exponential in the size of the graph

Laure Gonnord (UCB Lyon1) Graphs 2017 � 8 / 36 �

Page 9: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

Graph Coloring Problem

Color with the minimal number of colors !I Application to the register allocation in compilers.I The sudoku problem (9-coloring of a 81-vertices graph)

Laure Gonnord (UCB Lyon1) Graphs 2017 � 9 / 36 �

Page 10: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

Graph Coloring Problem - 2

Are you able to design a polynomial algorithm ?

Laure Gonnord (UCB Lyon1) Graphs 2017 � 10 / 36 �

Page 11: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

Graph Coloring Problem - 3

We do not know any polynomial algorithm for this problem.

Laure Gonnord (UCB Lyon1) Graphs 2017 � 11 / 36 �

Page 12: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

Graph Coloring Problem - A Polynomial algorithm

An algorithm to color a graph (but without optimising thenumber) with 6 K colors.Running example :

Laure Gonnord (UCB Lyon1) Graphs 2017 � 12 / 36 �

Page 13: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

Kempe’s simplification algorithm 1/2

On the interference graph (without coalesce edges) :

Proposition (Kempe 1879)Suppose the graph contains a node m with fewer than Kneighbours. Then if G′ = G \ {m} can be colored, then G canbe colored as well.

I Pick a low degree node, and remove it, and continue untilremove all (the graph is K-colorable) or . . .

Laure Gonnord (UCB Lyon1) Graphs 2017 � 13 / 36 �

Page 14: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

Kempe’s simplification algorithm 2/2

Laure Gonnord (UCB Lyon1) Graphs 2017 � 14 / 36 �

Page 15: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

Let’s color !We assign colors to the nodes greedily, in the reverseorder in which nodes are removed from the graph.The color of the next node is the first color that is available,i.e. not used by any neighbour.

Laure Gonnord (UCB Lyon1) Graphs 2017 � 15 / 36 �

Page 16: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

Greedy coloring example 1/2

Laure Gonnord (UCB Lyon1) Graphs 2017 � 16 / 36 �

Page 17: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

More difficult problems on graphs

Greedy coloring example 2/2

I see the Python implementation !

Laure Gonnord (UCB Lyon1) Graphs 2017 � 17 / 36 �

Page 18: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

1 More difficult problems on graphs

2 NP - completeness

3 Docs

Laure Gonnord (UCB Lyon1) Graphs 2017 � 18 / 36 �

Page 19: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

Complexity

The complexity of an implementation / an algorithm is linked toTuring machines :

The number of steps in the execution of a TM gives thecomplexity in time,The number of seen squares in the execution of a TMgives the complexity in space.

We can replace the TM by “a C implementation”.

Laure Gonnord (UCB Lyon1) Graphs 2017 � 19 / 36 �

Page 20: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

P Problems

PA problem (or a language) belongs to P if there exists adeterministic Turing Machine that gives the result inpolynomial time.

I there is a polynom p such that for all entry x, the Turingmachine stops (with the good result) in less than p(|x|) steps.

Example : L = anbncn, the TM of the previous course checksany aibici in O(n) steps

Laure Gonnord (UCB Lyon1) Graphs 2017 � 20 / 36 �

Page 21: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

P Problems

Integer multiplicationEulerian tour (each edge once)Linear programming (recall that polynomial diophantineequations are undecidible.)Primality test

http://www.cs.uu.nl/groups/AD/compl-diaz.pdf

Laure Gonnord (UCB Lyon1) Graphs 2017 � 21 / 36 �

Page 22: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

NP Problems

NPA problem (or a language) belongs to NP if there exists adeterministic Turing Machine that checks the result inpolynomial time.

Example : there exists a TM that is able to check if a given pathis an hamiltonien tour, in polynomial time.

Laure Gonnord (UCB Lyon1) Graphs 2017 � 22 / 36 �

Page 23: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

NP Problems - Examples

Factoring3-SAT (formulae in CNF with 3 litterals on each term)Hamiltonian tour3-colorability

http://www.cs.uu.nl/groups/AD/compl-diaz.pdf

Laure Gonnord (UCB Lyon1) Graphs 2017 � 23 / 36 �

Page 24: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

NP vs P - some facts

If a problem belongs to NP , then there exists anexponential brute-force deterministic algorithm to solve it(easy to prove)P ⊆ NP (trivial)

I P = NP ? P 6= NP ? Open question ! Problem of the millenium !Is finding more difficult that verifying ?

Laure Gonnord (UCB Lyon1) Graphs 2017 � 24 / 36 �

Page 25: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

NP-complete problems - 1

Given a problem :if we find a polynomial algorithm I Pif we find a polynomial time checking algorithm I NP, butwe want to know more :

“it it really hard to solve it ?”“is it worth looking for a better algorithm ?”

Laure Gonnord (UCB Lyon1) Graphs 2017 � 25 / 36 �

Page 26: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

NP-complete problems - 2

The key notion is the notion of polynomial reduction

Polynomial reduction of problemsGiven two problems P1 and P2, P1 reduces polynomially to P2 ifthere exists an f such that :

f is polynomialx1 solution of P1 iff f(x1) solution of P2.

Example : Hamiltonian circuit is polynomially reductible to TSP.

Laure Gonnord (UCB Lyon1) Graphs 2017 � 26 / 36 �

Page 27: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

NP-complete problems - 3

The most difficult problems in NP. All problems in NPC arecomputationally equivalent in the sense that, if one problemis easy, all the problems in the class are easy. Therefore, if oneproblem in NPC turns out to be in P, then

P=NP

Laure Gonnord (UCB Lyon1) Graphs 2017 � 27 / 36 �

Page 28: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

NP-complete problems - 4

Reminder : we want to characterise the most difficult problemsin NP.

NP-completeA problem is said to be NP-complete if :

It belongs to NPAll other problems in NP reduce polynomially to it.

In other words, if we solve any NP-complete in polynomial time,we have proved P = NP (and we become rich)

Laure Gonnord (UCB Lyon1) Graphs 2017 � 28 / 36 �

Page 29: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

NP-complete problems - 4

Problem : how to prove that a problem is NP-complete ?The very first one is hard to proveThen, we use the following result :

If two problems / languages L1 and L2 belong to NP and L1 isNP-complete, and L1 reduces polynomially to L2, then L2 is

NP-complete.

I Pick one NP complete problem and try to reduce it to yourproblem.

Laure Gonnord (UCB Lyon1) Graphs 2017 � 29 / 36 �

Page 30: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

NP-complete problems - The historical example

SATISFIABILITY is NP-complete (Cook, 1971)SAT reduces polynomially to 3SAT3SAT reduces polynomially to Vertex CoverVertex Cover reduces polynomially to Hamiltonian circuit

I “So”Hamiltonian circuit, then TSP are also NP-completeproblems

Laure Gonnord (UCB Lyon1) Graphs 2017 � 30 / 36 �

Page 31: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

Some NP-complete (common) problems

Some classical examples :Hamiltonian cycle and TSPGraph Coloring ProblemVertex coverKnapsack (integer)Flow shop problemSudoku

The book : Computers and Intractability : A Guide to the Theoryof NP-Completeness. A short list on the french webpage :http://fr.wikipedia.org/wiki/Liste_de_probl%C3%A8mes_

NP-complets

Laure Gonnord (UCB Lyon1) Graphs 2017 � 31 / 36 �

Page 32: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

Conclusion - 1

Laure Gonnord (UCB Lyon1) Graphs 2017 � 32 / 36 �

Page 33: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

NP - completeness

Conclusion - 2

Knowing that a given problem is NP complete is just thebeginning :

handle less general classes of inputscompute less precise solutions

Laure Gonnord (UCB Lyon1) Graphs 2017 � 33 / 36 �

Page 34: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

Docs

1 More difficult problems on graphs

2 NP - completeness

3 Docs

Laure Gonnord (UCB Lyon1) Graphs 2017 � 34 / 36 �

Page 35: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

Docs

More docs on graphs

In french : http://laure.gonnord.org/site-ens/mim/graphes/cours/cours_graphes.pdf or type “cours deThéorie des graphes” in GoogleIn english : an interactive tutorial here : http://primes.utm.edu/cgi-bin/caldwell/tutor/graph/intro.(en) The theorical book “Graph Theory”, R. Diestel(electronic version :http://diestel-graph-theory.com/basic.html)(en) e-book for algorithms : http://code.google.com/p/graph-theory-algorithms-book/

Laure Gonnord (UCB Lyon1) Graphs 2017 � 35 / 36 �

Page 36: Preparation CAPES - Difficult problems on graphs (notions ......NP - completeness NP-complete problems - 2 The key notion is the notion ofpolynomial reduction Polynomial reduction

Docs

More docs on complexity

The Book : computers and intractability, a guide to the theoryof NP completeness, by Garey/Johnson

Laure Gonnord (UCB Lyon1) Graphs 2017 � 36 / 36 �