Class Schedule Tuesday Thursday

advertisement
Class Schedule
Tuesday:
Thursday:
P & NP
P/NP-time reduction
Tuesday:
Thurs:
Approximate Algorithms
no class (thanksgiving)
Tuesday:
Thursday:
Friday:
Network Flow
Final Exam Review
Program 4 due
Polynomial-Time (P)
A class of decision problems for which there exists* polynomial time solutions.
decision problems: problems with Boolean answer/returns (like ‘is n prime?”)
* just because you find, use, or know a solution that is slower then polynomial
time, doesn’t mean that the problem isn’t a polynomial time problem. It
just means you’re solution is slower then it could be.
Question to be asked about P problems:
In terms of what are you measuring the run-time?
O(nk), where k = constant
// n = input size
Eg:
Is n prime?
For(I=2; I<sqrt(n); I++)
If (n%I==0) return false;
Return true;
Possibilities:
a) represent n in Unary -> size of input is n… O(sqrt(n))
b) represent n in Binary -> size is logn… O(nk/2)
therefore, the change in input size effects speed.
Non-deterministic Polynomial Time (NP)
A class of decision problems whose solution (in the affirmative) can be verified in
polynomial time.
Eg:
Solution:
A -> F is 14 or less
Verification:
3 + 6 + 4 = 13 <= 14
A -> C -> D -> F
Eg:
Solution:
Is 10 a composite numbers (non prime number)?
Yes
Verification:
2 * 5 = 10
Traveling Salesman Problem
Given a weighted graph G
Output: A circuit(cycle) that visits each vertex in G once and returns to the start vertex of
minimal weight.
Decision problem:
Given a graph G and a positive integer k, does there exist a circuit in G of weight
k or less?
Verify:
k = 100
6 +12 +15+20+ 5 + 8 = 66
A->D->B->F->C->E->A
(aside)
Homework
The next HW assignment has 3 main components.
1) Path Cost Calculator
2) Algorithm to approximate a solution given that the triangle inequality holds
3) Algorithm to approximate a solution given no additional information.
triangle inequality: 2 sides of a triangle added together must be equal to or greater then
the size of the 3rd side:
A
C
B A + B >= C
A + C >= B
B + C >= A
(back to the lecture)
Polynomial-time Reduction
A problem A reduces to a problem B in polynomial-time (A <= B) if x  A  f(x)  B
and f(x) is computable in polynomial time.
Eg:
A is a problem
A: partition problem (given a set of positive ints, determine whether or not you
can partition the set into 2 groups where the sum of each group is the same.
B: Subset-sum problem: given a set of positive ints and a target value T,
determine if there is a solution of the set that adds to T.
Try to solve the partition input: set S
set, int f(set S) { // retuns 2 things, kinda make believe, just go with it
sum = 0;
for (I = 1 to n) sum += S[i];
target = sum/2;
return S, target;
}
S = {8, 9, 3 , 4}
f(x): returns {8, 9, 3, 4} and 12.
12 is what each partition for problem A needs to add up to.
A: {8, 4} {9, 3} // both adds up to 12
B:
Partition(s) {
Return SS(f(s));
}
NP Complete
1) if it is NP Complete, it is NP
2) every other problem in NP reduces to it in polynomial time.
So, if any NP Complete problem is ever solved in polynomial time, then all other NP
Complete problems would have a polynomial solution too. As it stands, this has not
happened.
More NP Reduction on Thursday
Download