Docstoc

COMPLEXITY

Document Sample
COMPLEXITY Powered By Docstoc
					Mark Allen Weiss: Data Structures and Algorithm Analysis in Java




                      Complexity Issues




                                      Lydia Sinapova, Simpson College
                 Complexity Issues

v Class P problems
v Class NP problems
v NP-complete problems
v Non-NP problems
v Decidability




                                 2
               Class P Problems
Ø Polynomial run time in the worst-case
Ø "tractable" problems


Ø Examples
  Ø Simple sorting algorithms
  Ø Advanced sorting algorithm
  Ø Topological Sort
  Ø Shortest Paths
  Ø Min Spanning Trees
                                          3
                    Class NP Problems
NP-Problems: Problems for which there is no known
polynomial-time algorithms, "intractable" problems

NP means non-deterministically polynomial. If we
have a candidate for a solution, we can verify it in
polynomial time. The difficult part is to generate all
possible candidates.

Example: (the satisfiability problem) Given a boolean expression of
n variables, find a set of variable assignments that satisfy the
expression

Obviously, P Í NP, but P Ì NP (or P = NP) is an open question
                                                                      4
       NP-Complete Problems
An NP-Complete problem is an NP problem with the
property that any problem in NP can be reduced to it in
polynomial time


In 1971 Stephen Cook (currently working at the
University of Toronto, Ontario) showed that the
satisfiability problem is NP-complete by proving that
every other NP problem could be transformed to it.
http://www.cs.toronto.edu/DCS/People/Faculty/sacook.html


                                                        5
         NP-Complete Problems
Bin packing problem: How to pack or store objects of various sizes and
    shapes with a minimum of wasted space?

Clique problem: A clique is a subset K of vertices in an undirected graph
    G such that every pair is joined by an edge in G. The problems are:
    Given a graph G, and an integer k, does G have a clique consisting of
    k vertices?
    Given a graph G, find a clique with as many vertices as possible.

Knapsack problem: You have a knapsack with a given size and several
    objects with various sizes and values. The problem is how to fill your
    knapsack with these objects so that you have a maximum total value.

Hamiltonian Cycle: a cycle that contains all nodes of the graph. Proving
    that a graph has a Hamiltonian cycle is a NP-complete problem.

                                                                       6
         NP-Complete Problems
NP problems and non-NP problems:

For NP problems, given a candidate for a solution, we can verify it in
polynomial time.

For non-NP problems, we cannot verify in polynomial time whether
a candidate for a solution is a solution or not.

Example: the problem to prove that a graph does not have a
Hamiltonian cycle is a non-NP problem.

NP-hard problems: NP-Complete, but not necessarily in NP class


                                                                         7
                            Decidability


Yes/no problems (decision problems)
A decision problem is a question that has two 
possible answers yes or no. The question is 
about some input.  
       



                                                 8
                Examples of Yes/No
                          Problems
Given a graph G and a set of vertices K,   is K a 
clique?
Given a graph G and a set of edges M, is M a 
spanning tree?
Given a set of axioms (boolean expressions) 
and an expression, is the expression provable 
under the axioms?


                                                 9
   Decidable, semi-decidable, and
           undecidable problems

A problem is decidable if there is an algorithm 
(P or NP) that says yes if the answer is yes, 
and no otherwise.
A problem is semi-decidable if there is an 
algorithm that says yes if the answer is yes, 
however it may loop infinitely if the answer is 
no.
A problem is undecidable if we can prove that 
there is no algorithm that will deliver an 
answer.                                            10
    Example of semi-decidable
                     problem
Given a set of axioms, prove that an expression is true.
Problem 1: Let the axioms be:
AvB
AvC
~B
Prove A.

To prove A we add ~A to the axioms.
If A is true then ~A will be false and this will cause a
contradiction - the conjunction of all axioms plus ~A will result in
False

(A v B) L ~A = B
B L (A v C) = (B L A) v (B L C)
B L ~ B = False                                                        11
          Example of semi-decidable
                           problem
Problem 2: Let the axioms be:
AvB
AvC
~B
Prove ~A.

We add A and obtain:
(A v C) L A = A
(A v B) L A = A
A L ~B = A L ~B
(A L ~B) L (A v B) = A L ~ B
…..
This process will never stop, because the expressions we
obtain will always be different from False

                                                           12
                 Example of undecidable
                               problem
The halting problem
       Let LOOP be a program that checks other 
       programs for infinite loops:
 LOOP(P) stops and prints "yes" if P loops infinitely
 LOOP(P) enters an infinite loop if P stops
 What about LOOP(LOOP)?


http://www.cgl.uwaterloo.ca/~csk/washington/halt.html
                                                        13

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:7/24/2013
language:Latin
pages:13