CSCE 310J Data Structures & Algorithms CSCE 310J Data Structures & Algorithms
CSCE 310J Data Structures & Algorithms CSCE 310J Data Structures & Algorithms
http://www.cse.unl.edu/~goddard/Courses/CSCE310J
1 2
3 4
Optimization/Decision Optimization/Decision
Problems Problems
Optimization Problems: An optimization problem tries to find an optimal solution
» An optimization problem is one which asks, “What is the optimal A decision problem tries to answer a yes/no question
solution to problem X?” Many problems will have decision and optimization
» Examples: versions.
0-1 Knapsack » Eg: Traveling salesman problem
Fractional Knapsack optimization: find hamiltonian cycle of minimum weight
Minimum Spanning Tree decision: find hamiltonian cycle of weight < k
Decision Problems Some problems are decidable, but intractable:
» An decision problem is one which asks, “Is there a solution to as they grow large, we are unable to solve them in
problem X with property Y?” reasonable time
» Examples: » What constitutes “reasonable time”?
Does a graph G have a MST of weight ≤ W? » Is there a polynomial-time algorithm that solves the problem?
5 6
Page 1
The Class P Sample Problems in P
P: the class of decision problems that have Fractional Knapsack
polynomial-time deterministic algorithms. MST
» That is, they are solvable in O(p(n)), where p(n) is a
polynomial on n Single-source shortest path
» A deterministic algorithm is (essentially) one that Sorting
always computes the correct answer
Others?
Why polynomial?
» if not, very inefficient
» nice closure properties
» machine independent in a strong sense
7 8
11 12
Page 2
The Satisfiability (SAT) Conjunctive Normal Form
Problem (CNF) and 3-CNF
Satisfiability (SAT): Even if the form of the Boolean expression is
» Given a Boolean expression on n variables, can we
simplified, no known polynomial time algorithm exists
assign values such that the expression is TRUE? » Literal: an occurrence of a Boolean or its negation
» Ex: ((x1 →x2) ∨ ¬((¬x1 ↔ x3) ∨ x4)) ∧¬x2 » A Boolean formula is in conjunctive normal form, or CNF, if
it is an AND of clauses, each of which is an OR of literals
» Seems simple enough, but no known deterministic
Ex: (x1 ∨ ¬x2) ∧ (¬x1 ∨ x3 ∨ x4) ∧ (¬x5)
polynomial time algorithm exists
» Easy to verify in polynomial time!
» 3-CNF: each clause has exactly 3 distinct literals
Ex: (x1 ∨ ¬x2 ∨ ¬x3) ∧ (¬x1 ∨ x3 ∨ x4) ∧ (¬x5 ∨ x3 ∨ x4)
Notice: true if at least one literal in each clause is true
13 14
17 18
Page 3
NP-Hard and NP-Complete Proving NP-Completeness
If P is polynomial-time reducible to Q, we denote What steps do we have to take to prove a problem
this P ≤p Q Q is NP-Complete?
Definition of NP-Hard and NP-Complete: » Pick a known NP-Complete problem P
» If all problems R ∈ NP are reducible to P, then P is NP- » Reduce P to Q
Hard Describe a transformation that maps instances of P to instances
of Q, s.t. “yes” for Q = “yes” for P
» We say P is NP-Complete if P is NP-Hard
Prove the transformation works
and P ∈ NP
Prove it runs in polynomial time
If P ≤p Q and P is NP-Complete, Q is also » Oh yeah, prove Q ∈ NP (What if you can’t?)
NP-Complete
19 20
21 22
23 24
Page 4
Hamiltonian Cycle ⇒ TSP Hamiltonian Cycle ⇒ TSP
The well-known traveling salesman problem: The steps to prove TSP is NP-Complete:
» Optimization variant: a salesman must travel to n cities,
» Prove that TSP ∈ NP (Argue this)
visiting each city exactly once and finishing where he
begins. How to minimize travel time? » Reduce the undirected hamiltonian cycle problem to the
TSP
» Model as complete graph with cost c(i,j) to go from city i to
So if we had a TSP-solver, we could use it to solve the
city j hamilitonian cycle problem in polynomial time
How would we turn this into a decision problem? How can we transform an instance of the hamiltonian cycle
problem to an instance of the TSP?
» A: ask if ∃ a TSP with cost < k
Can we do this in polynomial time?
25 26
27 28
Review:
Review: NP-Complete Proving Problems NP-Complete
What, intuitively, does it mean if we can reduce
How do we usually prove that a problem R
problem P to problem Q?
is NP-Complete?
» P is “no harder than” Q
» A: Show R ∈NP, and reduce a known
How do we reduce P to Q? NP-Complete problem Q to R
» Transform instances of P to instances of Q in polynomial
time s.t. Q: “yes” iff P: “yes”
What does it mean if Q is NP-Hard?
» Every problem P∈NP ≤p Q
What does it mean if Q is NP-Complete?
» Q is NP-Hard and Q ∈ NP
29 30
Page 5
Other NP-Complete
Problems General Comments
K-clique
» A clique is a subset of vertices fully connected to each other, i.e. a Literally hundreds of problems have been shown
complete subgraph of G to be NP-Complete
» The clique problem: how large is the maximum-size clique in a
graph? Some reductions are profound, some are
» No turn this into a decision problem? comparatively easy, many are easy once the key
» Is there a clique of size k?
insight is given
Subset-sum: Given a set of integers, does there exist a
subset that adds up to some target T?
0-1 knapsack: when weights not just integers
Hamiltonian path: Obvious
Graph coloring: can a given graph be colored with k colors
such that no adjacent vertices are the same color?
Etc…
31 32
Page 6