21scheme vtu syllabus of visveraya technological university
P versus NP
1. P versus NP
The greatest unsolved problem in Computer Science
And perhaps all in Mathematics!
Rituraj Joshi
CSE ‘16
2. What is an efficient algorithm?
Polynomial times -
➢ O(n)
➢ O(n2
)
➢ O(n10
)
Logarithmic running times-
➢ O(log n)
➢ O(n log n)
Non-Polynomial time -
➢ O(2n
)
➢ O(n!)
3. The P Class (problems that have fast solutions)
The general class of problems for which some algorithm can provide an answer in
polynomial time.
● Searching (Binary, Linear)
● Sorting (Merge, Insertion, Quick, etc)
● Greatest Common Divisor
● Multiplication
● Shortest Paths (Dijkstra’s, Bellman-Ford, etc)
● Minimum cost spanning trees
● Rubik’s Cube
4. The NP Class (no fast solutions known)
The class of questions for which an answer can be verified in polynomial time is called
NP, which stands for non-deterministic polynomial time but there is no known way to
find an answer quickly.
● Integer Factorization
● Sudoku
● Traveling Salesman Problem
● Graph Coloring
● 3 - SAT
● Vertex Cover
● Subset Sum
● Independent Set
6. Sudoku
O (nm
)
n = no of possibilities in each
cell (i.e. 9)
m = no of unfilled cells
7. What it means ?
Are the problems that are easy to check, also easy to solve?
All problems in P, are also in NP.
If I can solve a problem quickly, I can verify the solution
quickly by just solving the problem quickly.
8. Factorization
● A teacher assigns homework assignment:
○ Factorize a large number that is the product of two primes
● Student: Given N, find p,q such that pq = N
○ Generate a solution
● Teacher: Given a student’s solution p,q, verify that pq = N
○ Check a solution
9. Factorization
● For small values of N:
○ E.g. - 63, we have 3*21 = 63
● For large values like :
● How will you solve ?
● No efficient solution known
Easy to check but difficult to find p,q such that pq = N for large values of N
10. Boolean Satisfiability
● Boolean variables x, y, z, ....
● 3 - SAT - each clause has at most 3 literals
● A clause is a boolean expression having variables connected by or of the form
( x || !y || z || …. || w )
● Formula - clauses connected by and in between
C1 & C2 & … & Cn
( x || y || z ) & ( x || !y ) & ( y || !z ) & ( !x || !y || !z )
● Find if an assignment of values either true or false to variables is possible such
that the whole expression evaluates to true or report no such assignment
exists
11. ( x || y || z ) & ( x || !y ) & ( y || !z ) & ( !x || !y || !z )
● x = True, y= True, z = False makes this true
( x || y || z ) & ( x || !y ) & ( y || !z ) & ( z || !x ) & ( !x || !y || !z )
● Now there is no satisfying assignment
● Generating a solution
○ Try each possible assignment x, y, z, …
○ N variables - 2N
assignments
● Is there a better algorithm? Not known
● Checking is easy!
Boolean Satisfiability
12. Independent Set
● Vertices u, v are independent if there is no edge (u, v)
● U is an independent set if each pair (u,v) in U is independent
● Constitute a neutral committee where none of the members know each other
● Find the largest independent set in a given graph
● Checking version: Is there an independent set of size K?
● Again, checking is easy!
13. Vertex Cover
● Node u covers every edge (u, v) incident on u
● U is a vertex cover if each edge in the graph is covered by some vertex in U
● Position surveillance cameras at intersections to watch all roads
● Find the smallest vertex cover in a given graph
● Checking version: Is there a vertex cover of size K ?
14. Connecting independent set and vertex cover
● U is an independent set of size K iff V-U is a vertex cover of size N-K
● =>
● Every edge (u, v) has at most one endpoint in U, so at least one endpoint in V-U
● <=
● For any edge (u, v), at least one endpoint in V-U, so no edges (u,v) within U
15. Traveling Salesman Problem
● A network of cities with distances between each pair
● A complete graph G = (V, E) with edge weights
● Find the shortest tour that visits each city exactly once
● Simple cycle x,y,z,...,x visiting all vertices, of minimum cost (Hamiltonian Cycle)
● Given a graph G and a proposed solution S we can
● Verify that S is a cycle
● Compute its cost
● How to check that S is the least cost cycle
16. Reductions
A reduction is a polynomial time algorithm that converts solution of one problem to
solution of another problem
● Independent set and vertex cover reduce to each other
● Recall: if A reduces to B and A is intractable, so is B
● Many pairs of checkable problems are inter-reducible
● All “equally” hard
18. What if P = NP?
It is said that world would profoundly be a very different place than it is now.
❏ Problems like protein folding will help us cure cancer
❏ RSA Encryption would be easy to crack (based on factoring)
❏ Artificial Intelligent systems would make huge leaps overnight
❏ Transportation scheduled optimally: people and goods moved around quickly and
cheaper
❏ Automatically generate mathematical proofs?
19. How to prove it?
● To prove P = NP
○ Give a polynomial time algorithm to any NP complete problem
● To prove P !=NP
○ Prove that there exists NO ALGORITHM to solve some NP problem in polynomial
time
Not an easy task!
20. NP Completeness
● SAT is said to be complete for NP
○ It belongs to NP
○ Every problem in NP reduces to it (Cook-Levin Theorem)
● If you can solve SAT, you can solve any NP problem
● Original proof is by recoding computations of Turing Machines
NP Hard
● Not sure if it belongs to NP
● Because checking algorithm is not there