P and NP - PowerPoint PPT Presentation

1 / 42
About This Presentation
Title:

P and NP

Description:

Graph Coloring and Chromatic Number Definitions. Let G=(V,E) be ... have different color. ... Optimization graph coloring problem (Find chromatic number for ... – PowerPoint PPT presentation

Number of Views:131
Avg rating:3.0/5.0
Slides: 43
Provided by: IRE62
Category:
Tags: coloring

less

Transcript and Presenter's Notes

Title: P and NP


1
P and NP
  • Irena Pevac
  • CS463

2
Definitions
  • Def Decision problem is a question that has two
    possible answers yes or no.
  • Def Problem instance is a combination of the
    problem and a specific input.
  • Decision problem has most often two parts
  • Instance description part
  • Defines the information expected in the input
  • Question part
  • States the actual yes no question. The question
    contains variables defined in the instance
    description.

3
Precise Statement of the Input
  • EXAMPLE 1
  • Input Instance an undirected graph G(V,E)
  • Question Does G contain a clique Ck (complete
    subgraph) of k vertices for some k?
  • (?k)(k 1,2,,n , Ck is a subgraph of G )
    ?
  • C1 OR C2 OR C3 OR Cn

4
  • EXAMPLE 2
  • Input Instance an undirected graph G (V,E) and
    an integer k
  • Question Does G contain a clique Ck (complete
    subgraph) of k vertices ?
  • ?
  • Ck is a clique and it is a subgraph of G.
  • If Question 2 is YES ? Question 1 is YES.
  • If Question 1 is YES ? Question 2 does not have
    to be YES.

5
Graph Coloring and Chromatic Number Definitions
  • Let G(V,E) be undirected graph.
  • Coloring is a mapping c V?S where S is a finite
    set of colors and if vw E then c(v)4c(w).
    (Adjacent vertices have different color.)
  • The chromatic number of G, denoted ?(G) is the
    smallest number of colors needed to color G.

6
Graph Coloring
  • Given G(V,E) undirected graph
  • OPTIMIZATION PROBLEM Given G, determine ?(G) and
    produce an optimal coloring, that is, one that
    uses only ?(G) colors.
  • DECISION PROBLEM Given G, and an integer k, is
    there a coloring of G using at most k colors. (If
    so, G is k colorable).

7
Geographic Map Coloring
8
Graph Coloring Application
  • Geographic map coloring
  • Nodes are states
  • Edge connects two nodes if they represent two
    adjacent states
  • Coloring is used to color the map.

9
Graph 4 Coloring of US Map
10
Scheduling Application
  • Scheduling finals for course-sections
  • Nodes are course sections.
  • Edges connect two sections that have at least one
    student in common.
  • Colors represent time slots for exams.
  • PROBLEM Schedule exams into minimal number of
    time slots, so that no student is scheduled more
    than one exam in the same time slot.

11
Graph 4 Coloring of Final Exams
12
Definitions
  • Def A propositional or boolean variable has
    value true or false.
  • Def A literal is a propositional variable or its
    negation.
  • Def A propositional formula is defined
    inductively
  • A constant true or false is propositional
    formula.
  • A propositional variable is propositional
    formula.
  • If F is propositional formula than NOT F is also
    propositional formula.
  • If F and G are two propositional formulas then F
    AND G and F OR G are also propositional formulas.

13
Conjunctive Normal Form CNF
  • Def Clause is a sequence of literals connected
    with OR operators.
  • L1 OR L2 OR L3 OR OR Ln
  • Def A propositional formula is in conjunctive
    normal form if it consists of a sequence of
    clauses connected by AND operators.
  • Def A truth assignment for a set of
    propositional variables is an assignment of TRUE
    or FALSE for each propositional variable in the
    set.

14
Satisfiability
  • Def A truth assignment is said to satisfy a
    formula if it makes the value of entire formula
    true.
  • A CNF formula is satisfied if each clause
    evaluates to true. A clause evaluates to true if
    at least one of its literals evaluates to true.
  • DECISION PROBLEM Given a CNF formula, is there a
    truth assignment that satisfies it?
  • DECISION PROBLEM Given a CNF formula, in which
    each clause has at most three literals, is there
    a truth assignment that satisfies it?

15
Hamiltonian Cycle and Path
  • Def A Hamiltonian cycle in an undirected graph
    is a simple cycle that passes through every
    vertex of the graph exactly once.
  • Def A Hamiltonian path in undirected graph is
    simple path that passes through every vertex of
    the graph exactly once.
  • Def A Traveling Salesman must visit every city
    once and return to the starting city at the end
    of the tour and travel the shortest possible
    path.
  • TSP is used in routing garbage pickups and
    package and mail deliveries.

16
Hamiltonian Cycle
17
  • DECISION PROBLEM Does a given undirected graph
    have a Hamiltonian cycle?
  • DECISION PROBLEM Does a given undirected graph
    have a Hamiltonian path?
  • OPTIMIZATION PROBLEM Given a complete weighted
    graph, find a minimum weight Hamiltonian cycle.
    (TSP)
  • DECISION PROBLEM Given a complete, weighted
    graph and an integer k, is there a Hamiltonian
    cycle with total weight at most k.

18
Polynomial Complexity
  • Def An algorithm is polynomially bounded if its
    worst case complexity is bounded by a polynomial
    function of the input size.
  • Def A problem is polynomially bounded if there
    exist a polynomially bounded algorithm that
    solves the problem.

19
Tractable and Intractable Problems
  • Tractable problems are those that can be solved
    in polynomial time.
  • Problems that cannot be solved in polynomial time
    are called untractable.

20
The Class P
  • Def The class P is class of decision problems
    that can be solved in polynomial time by
    deterministic algorithm.
  • Excluding problems not solvable in polynomial
    time makes sense because of exponentially large
    output in some problems
  • Listing all subsets of a given set
  • Listing all permutations of n different numbers

21
  • Some problems that are not decision problems can
    be reduced to a series of decision problems.
  • Optimization graph coloring problem (Find
    chromatic number for given graph) can be reduced
    to a series of decision problems.
  • Given G, is there a coloring of G using at most
    1 color.
  • Given G, is there a coloring of G using at most 2
    colors.
  • Given G, is there a coloring of G using at most 3
    colors.
  • Given G, is there a coloring of G using at most 4
    colors.
  • The first value for which decision problem has
    solution solves the optimization version of the
    graph-coloring problem as well.

22
Undecidable Problems
  • QUESTION Can every decision problem be solved in
    polynomial time?
  • ANSWER No! For some decision problems time is
    exponential.
  • For other decision problems no algorithm exists
    to solve it. This are undecidable algorithms.

23
Alan Turings Halting Problem
  • Alan Turings Halting Problem
  • Given a computer program and an input to it,
    determine whether the program will halt on that
    input or continue to work for ever.
  • Turings halting problem was one of the most
    important contributions to computer science made
    in 1936. Proof that problem is undecidable (i.e.
    no algorithm exists to solve the problem) is done
    by way of contradiction.

24
  • PROOF
  • Assume that A is an algorithm to solve the
    halting problem. That would mean that for any
    program P and any input I,
  • if program P halts on I
  • A(P,I)
  • if program P
    doesnt halt on I
  • We can consider program P as an input to itself
    and use the output of algorithm A for pair (P, P)
    to construct a program Q as follows

25
  • if A(P,P)0 i.e. P
    doesnt halt on I.
  • Q(P,I)
  • if
    A(P,P)1i.e. P halts on I.
  • On substituting Q for P we get
  • if Q(A,A)0,
    i.e. Q doesnt halt on I.
  • Q(Q)
  • if A(Q,Q)1, if
    Q halts on input I.
  • This is a contradiction.

26
Decidable Problems
  • We proved that halting problem is undecidable.
  • Are there decidable but untractable problems?
    Yes. There are.
  • There is a large number of problems for which no
    polynomial time algorithm exists, nor has the
    impossibility of such algorithm been proved.

27
Examples
  • Some such examples were mentioned earlier
  • Hamiltonian Circuit, Hamiltonian Path
  • Traveling Salesman
  • Graph Coloring
  • Some other famous examples
  • Partition Problem Given n positive integers,
    determine if it is possible to partition them
    into two disjoint sets with the same sum.
  • Bin Packing Given n items whose values are
    positive rational numbers not larger than 1, put
    them into the smallest number of bins of size 1.

28
Exponential v.s. Polynomial Time
  • All those examples have an exponential (or worse)
    growth of choices, as a function of input size.
  • Some of examples can be solved in polynomial
    time.
  • Eulerian circuit problem- problem of existence of
    a cycle that traverses all the edges of the given
    graph only once (Eulerian circuits) can be solved
    in O(n2).

29
Checking the Solution in Polynomial Time
  • Most of decision problems are expensive to solve,
    but testing whether a proposed solution solves
    the problem is easier (can be done in polynomial
    time).
  • Example To check whether a list of vertices is
    Hamiltonian circuit for a given graph G with n
    vertices we have to check
  • That each vertex on the lists belongs to V,
  • That first and last are the same, and that first
    n are all different.
  • That every two consecutive in the list are
    adjacent vertices in the graph (are connected
    with an edge).

30
Nondeterministic Algorithms
  • Def A nondeterministic algorithm is a two stage
    algorithm that takes as its input an instance I
    of a decision problem and does the following
  • Nondeterministic guessing phase. An arbitrary
    string of characters S is generated at the
    beginning. S may be considered as a guess of a
    solution for I but it may be a gibberish as well.
  • The deterministic verifying phase takes both I
    and S and outputs yes if S is solution for I,
    otherwise it either returns No or it may not
    halt at all.

31
Example
  • Nondeterministic Graph Coloring
  • Problem Determine if an undirected graph G is
    k-colorable.
  • The first phase of nondeterministic algorithm
    will write some string s. Second phase will
    interpret s as a coloring for G. To verify that
    the coloring is valid it verifies
  • 1) Check that there are n colors listed.
  • 2) Check that each ci is in range 1,,k.
  • 3) Scan the list of edges in G and check that for
    each edge uv cunot equal cv.
  • If all the tests are true, return yes. If s does
    not satisfy all three conditions, the verifier
    may return false or go into an infinite loop, and
    the algorithm produces no output for this
    particular execution.

32
G( V1,2,3,4,5, E(1,2)(1,4)(2,4)(2,3)(3,5)(
2,5)(3,4)(4,5))
  • Input instance is graph G and k4
  • Problem Is graph G 4-colorable?
  • We denote colors by letters
  • B(blue), R(red), G(green), Y(yellow), O(orange)
    rather than integers 1,5.
  • The table that follows gives a few possible
    strings s and values returned by the verifier.

33
(No Transcript)
34
  • Since there exists one possible input for which
    verifier returns true, the answer of the
    nondeterministic algorithm for the input G(
    V1,2,3,4,5, E(1,2) (1,4) (2,4) (2,3) (3,5)
    (2,5) (3,4) (4,5) ) and k 4 is yes.

35
NP Class of Algorithms
  • We say that nondeterministic algorithm solves a
    decision problem if and only if for every yes
    instance of the problem it returns yes on some
    execution.
  • A nondeterministic algorithm should be able to
    guess a solution at least once and be able to
    test its validity.
  • DEF NP Class is the class of algorithms that can
    be solved by nondeterministic polynomial
    algortihms.

36
P and NP
  • Most decision problems are in NP class.
  • Class P is subset of class NP
  • P?NP
  • If a problem is in P, we can use the
    deterministic polynomial-time algorithm that
    solves it in the verification stage of a
    nondeterministic algorithm and ignore string S
    from the deterministic stage.

37
NP Algorithms
  • Hamiltonian circuit, partition problem, decision
    versions of TSP, Graph coloring, the knapsack are
    in NP.
  • The Turing halting problem is not in NP.

38
Open Question
  • One of the most important open questions of
    theoretical computer science is
  • Is P a proper subset of NP, or are these two
    classes the same.
  • ?
  • P NP

39
PNP
  • If PNP it would follow that each of the many
    hundreds of difficult combinatorial decision
    problems can be solved by a polynomial time
    algorithm, despite the fact that computer
    scientists did not find the algorithms.
  • It is believed that
  • but there is no proof yet.

40
Most Scientist Believe

41
(No Transcript)
42
Theoretical Possibilities
Write a Comment
User Comments (0)
About PowerShow.com