13- np-complete-problems-i.pdf

Upload: harryi3t

Post on 14-Apr-2018

238 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    1/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    NP-Complete Problems - I

    The Story of Sissa and Moore

    Lesson of Exponential Growth

    Put one grain of rise in the first square of the chessboard, two in the second, four in the third, eight in theforth, . And so on.

    18,446,744,073,709,551,615 grains of rice

    Exponential Growth

    colonies of bacteria,

    cells in a fetus,

    transistor density in chips, the computer speed(Moores Law)

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    2/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    Moores Law

    Looks like providing a disincentive for

    developing polynomial algorithms ?

    if an algorithm is exponential, why not wait it out

    until Moore's law makes it feasible

    NOT Really!!!

    Claim:

    Moores Law

    Claim: a huge incentive for developing

    polynomial algorithms

    Why?

    Boolean Satisfiability (SAT) complexity is O(2n)

    Sorting complexity is O(n logn)

    Year Variables (SAT) Sorting

    1975 25 100

    1985 31 100

    1995 38 100

    2005 45 100

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    3/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    The Story of Sissa and Moore

    The Morale of the Story:

    Exponential algorithms make polynomially slow progress,

    while polynomial algorithms advance exponentially fast

    Exponential expansion is not sustainable!

    Bacterial colonies run out of food

    Electronic chips hit the atomic scale

    Moore's law will stop doubling the speed of our computers within

    a decade or two

    The progress will depend on algorithmic ingenuity, orsome other new idea

    Problem Solving

    Shortest paths, MSTs, LCS, MCM, and manyothers

    We know that we can solve them efficiently, though

    we are searching for a solution (path, tree, matching,etc.) from among an exponential population ofpossibilities

    The quest for efficient algorithms

    is about finding clever ways to bypass this process ofexhaustive search, using clues from the input in orderto dramatically narrow down the search space

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    4/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    So far So Good!

    Algorithmic techniques that defeat the specter

    of exponentiality:

    Greedy algorithms, Dynamic programming, Divide

    and conquer, Linear Programming

    Now, the time has come to meet the quest's

    most embarrassing and persistent failures

    For some other search problems, the fastest

    algorithms we know for them are all exponential

    Difficult Problems

    If a problem has an O(nk) time algorithm

    (where n being the input size and k is a

    constant), then we class it as having

    polynomial time complexity and as being

    efficiently solvable

    If there is no known polynomial time

    algorithm, then the problem is classed as

    intractable, or difficult, or Hard Problem.

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    5/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    Euler vs. Rudrata Tours

    The dividing line is not always obvious.

    Consider two apparently similar problems:

    Euler's problem

    (often characterized as the Bridges of Knigsberg -

    a popular 18th Century puzzle)

    Rudrata's (Hamiltonian) problem

    (after the great Irish mathematician who

    rediscovered it in the 19th century)

    The Eulers Problem

    The 18th century German city of Knigsberg

    was situated on the river Pregel

    The puzzle asks whether it is possible to take a

    tour through the park, crossing each bridge

    exactly onceA

    DB

    C

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    6/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    The Eulers Problem

    An exhaustive search requires starting at every

    possible point and traversing all the possible

    paths from that point - an O(n!) problem.

    Eulerian Tour

    Euler showed that an Eulerian Tour existed iff

    1. it is possible to go from any vertex to any other by

    following the edges (the graph must be connected),

    and

    2. every vertex must have an even number of edges

    connected to it, with at most two exceptions (which

    constitute the starting and ending points).

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    7/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    Eulers Tour vs. Rudratas Tour

    Thus we now have a O(n) problem todetermine whether a path exists

    We can now easily see that the Bridges ofKnigsberg does not have a solution

    A quick inspection shows that it does have aHamiltonian path

    However there is no known efficient

    algorithm for determining whether aRudratas tour exists.

    The Rudratas Problem

    Can one visit all the squares of the chessboard,

    without repeating any square, in one long walk that

    ends at the starting square and at each step makes a

    legal knight move?

    Also known as

    The Knight Tour Problem

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    8/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    The Rudratas Problem

    The General Problem:

    given a graph, find a cycle that visits each vertex

    exactly onceor report that no such cycle exists Now known as Hamiltonian Cycle

    Class P and NP

    Euler's problem lies in the class P: problems

    solvable in Polynomial time

    Hamilton's problem is believedto lie in class

    NP (Non-deterministic Polynomial)

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    9/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    Class P and NP

    What is a Search Problem?

    any proposed solution can be quickly checked forcorrectness (in Polynomial Time)

    A search problem is specified by an algorithm C thattakes two inputs, an instance I and a proposedsolution S, and runs in time polynomial in (I), i.e.

    We say S is a solution to I if and only ifC (I, S) = true

    All search problems are NP

    The class of all search problems that can besolved in polynomial time is denoted P

    The Famous Problem: P NP ?

    The Common Belief is that P NP

    Otherwise, we need no Mathematician!!!

    However, NO PROOF!

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    10/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    Hard Problems and Easy Problems

    NP Complete Problems

    If P NP then we know that P is GOOD!

    What about the problems on the left side of

    the table?

    all, in some sense, exactly the same problem

    we show that these problems are the hardest

    search problems in NP, so that

    if even one of them has a polynomial time

    algorithm, then every problem in NP has a

    polynomial time algorithm

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    11/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    NP-Complete Problems

    There is a special class of problems in NP: the

    NP-complete problems.

    All the problems in NP are efficiently reducible

    to them.

    By efficiently, we mean in polynomial time, so

    the termpolynomially reducible provides a

    more precise definition

    Reduction

    The Hardest Search Problems:

    A search problem is NP-complete if all other

    search problems reduce to it

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    12/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    The Space of NP (Assuming P NP)

    Reduction

    A B (A is Polynomial Time Reducible to B)

    Efficient Problems: If B is efficient then C is alsoefficient

    Hard Search Problems (NP Complete): If A is hardthen B is also hard

    So if A is NP-complete,

    a new search problem B is also NP-complete,simply by reducing A to B

    This is how the set of NP-Complete problems hasgrown since then

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    13/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    Satisfiability (SAT)

    A Problem of great importance

    chip testing

    computer design

    image analysis

    software engineering, and others

    A canonical hard problem

    Satisfiability

    An Example

    a collection of clauses, each consisting of the disjunction of

    several literals,

    a literal is either a Boolean variable (such as x) or the

    negation of one

    The SAT Problem:

    given a Boolean formula in conjunctive normal form, either

    find a satisfying truth assignment of the Boolean variables

    or else report that none exists.

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    14/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    Satisfiability

    Interestingly

    1-SAT and 2-SAT are in P

    3-SAT is NP-Complete

    A generalized SAT can be reduced to 3-SAT

    Travelling Salesperson (TSP)

    Another famous hard problem (NP-C)

    Nave complexity is O(Factorial (n-1))

    A DP solution (still exponential) is follows

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    15/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    TSP

    A DP Solution

    Sub-Problems?

    let C (S, j) be the length of the shortest path

    visiting each node in S exactly once, starting at 1

    and ending at j

    For |S| > 1, we define

    Travelling Salesperson A DP Solution

    The Algorithm

    Time Complexity?

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    16/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    Reductions Again

    RUDRATA (s, t) PATH RUDRATA CYCLE ?

    RUDRATA CYCLE problem: given a graph, is

    there a cycle that passes through each vertex

    exactly once?

    RUDRATA (s, t)- PATH problem: given a graph

    with two vertices s and t, and we want a path

    starting at s and ending at t that goes through

    each vertex exactly once

    RUDRATA PATH RUDRATA CYCLE

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    17/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    RUDRATA PATH RUDRATA CYCLE

    We have to consider both the cases

    When the instance of RUDRATA CYCLE has a

    solution

    When the instance of RUDRATA CYCLE does not

    have a solution

    More on NP-Completeness

    See the next lecture

  • 7/30/2019 13- NP-Complete-Problems-I.pdf

    18/18

    CS 306 DAA, IIITDM Jabalpur 11/7/20

    Summary

    Polynomial Time Complexity Problems which have solutions withtime complexity O(nk) where k is a constant are said to havepolynomial time complexity.

    Class P Set of problems which have solutions with polynomial timecomplexity.

    Non-deterministic Polynomial (NP) A problem which can be solvedby a series of guessing (non-deterministic) steps but whose solutioncan be verified as correct in polynomial time is said to lie in class NP.

    Eulerian Path Path which traverses each arc of a graph exactly once A P-time problem

    Hamiltonian Path Path which passes through each node of a graphexactly once An NP-Complete problem

    NP-Complete Problems Set of problems which are all related toeach other in the sense that if any one of them can be shown to bein class P, all the others are also in class P.

    References

    Chapter 8, Algorithms by S. Dasgupta, C.H.

    Papadimitriou, and U.V. Vazirani