16
NP Complete 1 Joe Meehean

1 Joe Meehean. Log: binary search in sorted array Linear: traverse a tree Log-Linear: insert into a heap Quadratic (N 2 ): your sort from P1

Embed Size (px)

Citation preview

Page 1: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

1

NP Complete

Joe Meehean

Page 2: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

2

Complexities we’ve seen

Log: binary search in sorted array

Linear: traverse a tree

Log-Linear: insert into a heap

Quadratic (N2): your sort from P1 Exponential (NN): brute force

map coloring

Page 3: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

3

Polynomial Time Upper bound is Nk for N inputs

• e.g., O(logN), O(N), O(NlogN), O(N2), … Problems in class P

• have known polynomial time solutions

Page 4: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

4

Non-deterministic vs. Deterministic

Slipping into computational theory Deterministic programs

• like the ones we write in C++• must search or construct the correct answer• if there are many possible solutions must

check them all• OR carefully construct the answer piece-

wise

Page 5: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

5

Non-deterministic vs. Deterministic

Non-deterministic programs• currently exist only in theory• program guided by all knowing oracle• oracle can create a possible solution to the

problem for free• solution is often the correct one

if a solution exists

Page 6: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

6

Non-deterministic Polynomial Time

Think about reducing problem to yes/no

Given a potential solution to problem• is it possible to determine whether it is

correct in polynomial time Problems like this are in the NP class

• if in NP, but not P then there is no known polynomial time solution for these problems

• but we can check answers in polynomial time

Page 7: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

7

Non-deterministic Polynomial Time

e.g., graph coloring• given a potential coloring of vertices• for each vertex compare its colors to

its neighbors • O(E + V) = polynomial time• only need one correct k coloring to prove

graph can be colored with k colors

Page 8: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

8

Problem Complexity

NP

P

Page 9: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

9

NP Complete Problems Hardest problems in NP Any problem in NP can be polynomially

reduced to all NP complete problems• NP problem A can be translated into NP

complete problem B in polynomial time• e.g. calculator

numbers entered in decimal converted to binary and solved in binary converted back to decimal

Min color graph coloring is NP complete

Page 10: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

10

Problem Complexity

NP

P NP Complete

maybe

Page 11: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

11

NP Complete If we can solve an NP complete

problem A in polynomial time• we can use it as a method (sub routine) to

solve other NP problem B• just translate the B into A in polynomial

time• solve A• translate solution back into B• polynomial time + polynomial time =

polynomial time

Page 12: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

12

NP Complete If we can solve an NP complete

problem A in polynomial time• we can solve ALL NP problems in

polynomial time• P = NP

Page 13: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

13

Problem Complexity

NP

P

NP Complete

Page 14: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

14

NP Complete P = NP? No one has solved an NP complete

problem in polynomial time …Yet

Page 15: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

15

Undecidable problems Problems that are impossible to

solve using a Turing machine-based computer• impossible to solve with modern

computers E.g., halting problem

• does a program have an infinite loop?• proof is simple to explain• proof is hard to understand

involves recursion and impossible outcomes

Page 16: 1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1

16

Questions?