COSC 336: P, NP, NPcomplete problems - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

COSC 336: P, NP, NPcomplete problems

Description:

Hamiltonian circuit problem: Why is it in NP? ... Hamiltonian circuit: Given a candidate path, can test in linear time if it is a ... – PowerPoint PPT presentation

Number of Views:114
Avg rating:3.0/5.0
Slides: 20
Provided by: dans169
Category:

less

Transcript and Presenter's Notes

Title: COSC 336: P, NP, NPcomplete problems


1
COSC 336 P, NP, NP-complete problems
2
Polynomial versus Exponential Time
  • Most of our algorithms so far have been O(log N),
    O(N), O(N log N) or O(N2) running time for inputs
    of size N
  • These are all polynomial time algorithms
  • Their running time is O(Nk) for some k gt 0
  • Exponential time BN is asymptotically worse than
    any polynomial function Nk for any k
  • For any k, Nk is ?(BN) for any constant B gt 1

3
How bad is exponential time?
4
Feasible/Unfeasible Problems
  • Question When we should declare a problem to be
    practically solvable?
  • The answer is YES, it it can be solved by an alg.
    running in O(n), O(n log n), O(n2).
  • The answer is NO, if it can only be solved in
    exponential time.
  • Where do we draw the line?
  • Answer at polynomial time. O(nk), for a
    constant k.
  • DEF A problem is feasible if it can be solved by
    an algorithm running in time O(nk) for constant
    k.
  • Otherwise, it is unfeasible.

5
Polynomial-time reduction
  • DEF Problem A is polynomial-time reducible to
    problem B, if there exists a polynomial-time
    algorithm that solves A using an oracle for
    problem B.
  • Think of oracle as a subroutine that solves B. A
    call to this subroutine counts as one operation.
  • Notation A ?p B
  • Allows us to compare problems.
  • We can say If we could solve B in poly. time,
    we could solve A in poly. Time.
  • Or Problem B is not easier than problem A.

6
Example of reduction
  • Problem A (FACTORING). Given n (where n p
    q , and p and q are prime numbers), find p and
    q.
  • Problem B (MOD SQRT) Given n (where n p q,
    and p and q are prime numbers), find x ? 1,
    such that x2 1 (mod n).
  • FACTORING ?p MOD SQRT. (shown in class)
  • FACTORING is believed to be hard (no poly.-time
    algorithm is known for it)
  • This means that if we have access to an algorithm
    that solves MOD SQRT, then we could solve
    FACTORING fast.

7
Key Theorem on poly-time reductions
  • TH If A ?p B, and B is feasible, then A is
    feasible.
  • Also if A is not feasible, then B is not
    feasible.

8
Decision Problems
  • A decision problem is of the form
  • Input something (e.g., a graph, a list of
    numbers, )
  • Question Does the input have a certain property?
    Answer YES or NO.
  • Example 1
  • Input n , a positive integer.
  • Question Is n prime?
  • Example 2
  • Input G, a graph.
  • Question Is G connected?
  • We restrict our discussion to decision problems
    only.
  • Why The theory is more clear in this case, and
    typically most problems reduce do decision
    problems.

9
The Complexity Class P
  • The set P is defined as the set of all decision
    problems that can be solved in polynomial worst
    case time
  • Also known as the polynomial time complexity
    class
  • All decision problems that have some algorithm
    whose running time is O(Nk) for some k
  • Examples of problems in P Is a graph connected,
    is alist sorted, is there a path of cost k
    between s and t, etc.

10
The Complexity Class NP
  • Definition NP is the set of all problems for
    which a given candidate solution can be checked
    in polynomial time
  • Example of a problem in NP
  • Hamiltonian circuit problem Why is it in NP?
  • Given a candidate path, can test in linear time
    if it is a Hamiltonian circuit just check if
    all vertices are visited exactly once in the
    candidate path (except start/finish vertex)

11
NP- formal definition
  • A decision problem B is in NP if there exists a
    polynomial-time algorithm VER with the following
    properties
  • (1) for every YES instance x of B, there exists
    w of length polyn. in the length of x, such that
    VER(x,w) YES
  • (2) for every NO instance of B, for all w of
    length polyn, in the length of x,
  • VER(x,w) NO.
  • So, for YES instance, there exists a witness w,
    that the Verifier algorithm can check is a
    solution for x
  • And, for NO instances, there is no false witness
    that can fool the Verifier algorithm.

12
Why NP?
  • NP stands for Nondeterministic Polynomial time
  • Why nondeterministic? Corresponds to
    algorithms that can guess a solution (if it
    exists) ? the solution is then verified to be
    correct in polynomial time
  • Nondeterministic algorithms are not useful in
    practice purely theoretical idea invented to
    understand how hard a problem could be
  • Examples of problems in NP
  • Hamiltonian circuit Given a candidate path, can
    test in linear time if it is a Hamiltonian
    circuit
  • Sorting Can test in linear time if a candidate
    ordering is sorted
  • Are any other problems in P also in NP?

13
More Revelations About NP
  • Are any other problems in P also in NP?
  • YES! All problems in P are also in NP
  • Notation P ? NP
  • If you can solve a problem in polynomial time,
    can definitely verify a solution in polynomial
    time
  • Question Are all problems in NP also in P?
  • Is NP ? P?
  • I wished I could tell you that NP ? P, but I
    cant
  • Instead, I will tell you about NP-Complete
    problems

14
Another NP Problem
  • SAT Given a formula in Boolean logic, e.g.
  • determine if there is an assignment of values to
    the variables that makes the formula true (1).
  • 3-SAT Same but for boolean formulas having the
    following special format formula is an AND of
    clauses and each clause is an OR of exactly 3
    literals
  • Why is it in NP?

15
NP-Complete problems
  • DEF A problem B is NP complete if
  • (1) B is in NP
  • (2) Any problem A in NP is poly-time reducible to
    B
  • Thus In some sense B is the hardest problem in
    NP, because if we could solve it, then we could
    solve all problems in NP efficiently.

16
3-SAT is NP-Complete
  • Thus, if we knew how to solve SAT in poly-time,
    then there is a way to solve ANY NP problem in
    polynomial time !!!
  • This is strong evidence that SAT is not feasible.
  • After the Cook-Levin theorem has been proved,
    thousands of other problems have been shown to be
    NP-complete.

Theorem (Cook-Levin, 1971) 3-SAT is NP-complete.
17
How to show that a given problem is NP-complete
  • TH If A is NP-complete, B is in NP, and A ?p B,
    then B is NP-complete.
  • Why (sketch of proof) Any problem C can be
    solved in poly time with oracle access to A
    (because A is NP complete). We can replace
    queries to the A-oracle, by a poly-time algorithm
    that has oracle access to B. In this way we can
    solve C in poly-time with oracle access to B.
  • CLIQUE problem
  • Input a graph G (V,E) and a natural number k.
  • Question Does G have a clique of size k?
  • TH 3-SAT ?p CLIQUE. (shown in class). So,
    CLIQUE is NP-complete.
  • VERTEX COVER problem
  • Input a graph G (V,E) and a natural number k.
  • Question Are there k vertices so that it every
    edge of G is adjacent to at least one of them?
  • TH CLIQUE ?p VERTEX COVER. (shown in class).
    So, VERTEX COVER is NP-complete.

18
  • SUBSET SUM problem
  • Input A set of numbersA k_1, k_2, , k_n
    and additional number t
  • Question Is there a subset of A, whose sum is
    equal to t ?
  • Th 3-SAT ?p SUBSET SUM. So SUBSET SUM is
    NP-complete.

19
A Great Book with a list of NP-complete problems
  • Computers and Intractability A Guide to the
    Theory of NP-Completeness, by Michael S. Garey
    and David S. Johnson
Write a Comment
User Comments (0)
About PowerShow.com