Title: Hard or Intractable Problems NPComplete Problems
1Hard or Intractable Problems(NP-Complete
Problems)
- ECE573 Data Structures and Algorithms
-
- Electrical and Computer Engineering Dept.
- Rutgers University
- http//www.cs.rutgers.edu/vchinni/dsa/
2Polynomial or Intractable?
- Polynomial time complexity
- O(nk) time algorithm, k constant
- Intractable
- No O(nk) algorithm is known
- O(nn) or O(n!) or O(kn) time required
No HW6 PA6 We got to build this lost piece of
art work Can have some additional time
3Similar Problems?
- Eulers Problem
- Is there a path through a graph which traverses
each edge only once? - Hamiltons Problem
- Is there a path which visits each vertex only
once?
4Eulers Problem The Bridges of Königsberg
- Can I make a tour through the park, crossing
each bridge only once?
5Eulerian Path
- An Eulerian Path exists iff
- It is possible to go from any vertex to any other
by following the edges (graph must be connected) - Every vertex must have an even number of edges
connected to it -with at most two exceptions
(the start and end points) -
Obviously necessary conditions Sufficiency proof
may be found in the literature
6Transform the Bridges Problem
- Nodes land
- Edges bridges
- No path!
- Determined in O(n) time
- Count degree of each vertex
- Hamiltonian Path?
7Hamiltonian Path
- Although a path may be easily found in this case,
no known efficient algorithm for finding a
Hamiltonian path - But if we find a path,
- we can verify that it is a Hamiltonian path in
polynomial time - Check that each edge in the path is an edge in
the graph (use adjacency matrix) - O(E) - Check that each vertex is visited once only
-O(n2)
8Classes P and NP
- Class P
- Problems solvable in polynomial time
- eg Eulers problem
- Class NP
- Non-deterministic Polynomial
- eg Hamiltons problem
9Class NP
- Non-deterministic Polynomial
- At each step, guesswhich step to take next(eg
which vertex to check) - Have you found a correct solution?
- Need polynomial time only
- Nothing from previous steps guides the next step
- You have to try all possibilities
- O(n!) algorithms
Non-deterministic part You simply guess!
10Winning the Turing Award
- No proof that any problem ? class NP
- Problems (eg Hamiltonian path) are believed to be
in class NP - Because no polynomial time algorithm is known
- Proving that a problem ? class NP
or finding a class P algorithm ?Instant
fame!
Computings equivalent of the Nobel Prize
11Composite Numbers
- Determine whether a number n can be written as
the product of two other numbers - If the divisors can be found, then its simple to
verify that they are divisors - But, no efficient method of finding them is known
12Assignment Problem
- You have to assign students to rooms in a college
- You have a compatibility map
- Students are vertices,
- Compatible students are linked by an edge
- If rooms hold 2 students,
- a class P algorithm
- but if rooms hold 3 students,
- a class NP problem!
13Boolean Satisfiability
- Find an assignment of values (true or false) to
ai so that - is true
- where op are boolean operators and, or, ...
- Equivalent to circuit satisfiability problem
- Find a set of inputs which produce a true at the
output of a circuit composed of logic gates - Solution
- Try all 2n possible assignments
a1 op a2 op a3 ... op an
14Map Coloring
- Color a map using only three colors, so that
adjoining countries dont have the same color - Easily answered for 2 colors
- point at which an odd numberof countries meet
no solution - Solvable for 4 colors
- proof exists that 4 colors suffice for any map
15Map Coloring - Equivalent Problems
- Graph equivalent
- Vertices countries
- Edges connect countries with common borders
- Work scheduling
- Vertices tasks
- Edges represent common resources
- eg linked tasks require some machine
- 3 color marking of the vertices
- allocation of tasks to 3 shifts in a day
16Reducing Problems
- Map Coloring ? Boolean Satisfiability
- A solution can be constructed by assignment of
true or false to a set of variables
ar true ? A is red
ab true ? A is blue
ag true ? A is green
br true ? B is red
Solution If we can find a set of values for ax,
bx, ... which make this expression true, weve
found a map coloring
((ar ab ag ) (bb br. ... ) (cb
...
17NP-Complete Problems
- Special class of problems in NP
- The NP-complete problems
- All problems in NP are efficiently reducible to
them - Efficiently in polynomial time
- Many problems have been shown to be efficiently
reducible to boolean satisfiability - but an efficient solution to this (and thus any
other NP-complete problem!) has eluded many
researchers for a long time! - Its believed that class NP ? class P
18Solving NP-Complete problems
- NP problems are solvable
- Its just a question of patience (or longevity!)
- Non-deterministic algorithms
- Alternately
- Non-deterministic (guessing) step
- Select the next step randomly
- No guidelines any step may be the solution
- Deterministic step
- Determine (in polynomial time) whether you have
found a solution or not
19The Travelling Salesman Problem
- A salesman has a number of cities which he must
visit, find the minimum cost tour - Optimization problem
- Can we reduce it to boolean satisfiability?
- Problem must have a true /false answer
- Recast as
- Does a tour exist with cost less than x?
- Reduce x until the answer is provably no ...
- Optimal tour
- This problem may be proved equivalent to finding
a Hamiltonian circuit
20The Travelling Salesman Problem
- Many real world problems map to TSP
- Drilling circuit boards
- Inspection tours
- ...
- How do we solve it?
- Heuristics
- Approximate techniques leading to near-optimal
solutions - If you find the optimal solution, will you know?
21Travelling Salesman Heuristics
- Start with the Minimum Spanning Tree
- Optimal tour cost lt 2 MST cost
- Heuristics
- Christofides algorithm
- Prune the tour by taking short-cuts
- Tour must be an Eulerian path
- Each vertex of even degree
- Add edges to odd degree vertices
- Christofides algorithm produces a tour lt 1.5
optimal tour cost
22Travelling Salesman Heuristics
- Banding
- Divide the region into bands
- Number of citiesin each bandsufficiently small
that the TSPproblem can be solved by
exhaustion(brute-force or try all solutions) - Greedy algorithm to join the band solutions
23Travelling Salesman Heuristics
- Genetic algorithms
- Biological evolution analogy
- Reasonably effective
- Trivially parallelizable!
- Simulated annealing
- Model Annealing of solid
- Solution heads towards local minimum
- Temperature allows some probability of climbing
hills to escape a local minimum
24Games
- Search trees can be huge
- Chess 40 possible choices for each move
- 10-move look-ahead needed to win
- gt4010 positions to explore
- Modern computers just touching this capability
- Pentium _at_ 1000MHz 105 evaluations/second
- Still a rather boring game ... 1 month/move??