▪ Decision Problems v.s. Optimization Problems
▪ Complexity Classes
▪ P v.s. NP
▪ NP, NP-Complete, NP-Hard
2
▪
Design Strategy
▪ Divide-and-Conquer
▪ Dynamic Programming
▪ Greedy Algorithms
▪ Graph Algorithms
▪
Analysis
▪ Amortized Analysis
▪ NP-Completeness
4
▪
For an input with size n, the worst-case running time is for some constant k
▪
Problems that are solvable by polynomial-time algorithms as being tractable, easy , or efficient
▪
Problems that require superpolynomial time as being
intractable, or hard, or inefficient
▪ Use total four colors s.t. the neighboring parts have different colors
▪ Finally proven (with the help of computers) by Kenneth Appel and Wolfgang Haken in 1976
▪ Their algorithm runs in O(n2) time
▪ First major theorem proved by a computer
▪ Open problems remain...
▪ Linear time algorithms to find a solution
▪ Concise, human-checkable, mathematical proofs
6
▪ Given a planar graph G (e.g., a map), can we color the vertices with k colors such that no adjacent vertices have the same color?
▪ k = 1?
▪ k = 2?
▪ k = 3?
▪ k ≥ 4?
How hard is it when k = 3?
8
9
▪ Definition: the answer is simply “yes” or “no” (or “1” or “0”)
▪ MST: Given a graph 𝐺 = 𝑉, 𝐸 and a bound 𝐾, is there a spanning tree with a cost at most 𝐾?
▪ KNAPSACK: Given a knapsack of capacity 𝐶, a set of objects with weights and values, and a target value 𝑉, is there a way to fill the knapsack with at least 𝑉 value?
10
▪ Definition: each feasible solution has an associated value, and we wish to find a feasible solution with the best value (maximum or minimum)
▪ MST-OPT: Given a graph 𝐺 = 𝑉, 𝐸 , find the minimum spanning tree of 𝐺
▪ KNAPSACK-OPT: Given a knapsack of capacity 𝐶 and a set of objects with weights and values, fill the knapsack so as to maximize the total value
12
How to convert an optimization problem to a related decision problem?
Imposing a (lower or upper) bound on the value to be optimized
▪ Every optimization problem has a decision version that is no harder than the optimization problem.
▪ Using Aopt to solve Adec
▪ check if the optimal value ≤ k, constant overhead
▪ Using Adec to solve Aopt
▪ apply binary search on the value range, logarithmic overhead
Aopt: given a graph, find the length of the shortest path
Adec: given a graph, determine whether there is a path ≤ k
Textbook Chapter 34 – NP-Completeness
14
▪ Algorithmic design methods to solve problems efficiently (polynomial time)
▪ Divide and conquer
▪ Dynamic programming
▪ Greedy
▪ “Hard” problems without known efficient algorithms
▪ Hamilton, knapsack, etc.
▪ Can we decide whether a problem is “too hard to solve” before investing our time in solving it?
▪ Idea: decide which complexity classes the problem belongs to via reduction
▪ 已知問題A很難。若能證明問題B至少跟A一樣難,那麼問題B也很難。
16
▪
Algorithm design
▪ Design algorithms to solve computational problems
▪ Mostly concerned with upper bounds on resources
▪
Complexity theory
▪ Classify problems based on their difficulty and identify relationships between classes
▪ Mostly concerned with lower bounds on resources
upper bound
Problem Problem B
Problem A
lower bound
▪
A complexity class is “a set of problems of related resource- based complexity”
▪ Resource = time, memory, communication, ...
▪
Focus: decision problems and the resource of time
18
▪
The class P consists of all the problems that can be solved in polynomial time.
▪ Sorting
▪ Exact string matching
▪ Primes
▪ …
▪
Polynomial time algorithm
▪ For inputs of size n, their worst-case running time is for some constant k
20
▪
NP consists of the problems that can be solved in non- deterministically polynomial time.
▪
NP consists of the problems that can be “verified” in polynomial time.
▪
P consists of the problems that can be solved in (deterministically) polynomial time.
Non-Deterministic
initial
configuration
22
initial
configuration
This is not a randomized algorithm.
Non-Deterministic-Bubble-Sort(n) for i = 1 to n
for j = 1 to n – 1
if A[j] < A[i+1] then
Either exchange A[j] and A[i+1] or do nothing
▪
Input: a graph G
▪
Output: a smallest vertex subset of G that covers all edges of G.
▪
Known to be NP-complete
24
26
▪ Input: a Graph G and an integer k.
▪ Output: Does G contain a vertex cover of size no more than k?
▪ Original problem → optimization problem
▪ 原先的路燈問題是要算出放路燈的方法
▪ Yes/No → decision problem
▪ 問k盞路燈夠不夠照亮整個公園
Non-Deterministic-Vertex-Cover(G, k) set S = {}
for each vertex x of G
non-deterministically insert x to S if |S| > k
output no
if S is not a vertex cover output no
output yes
28
▪ If the correct answer is yes, then there is a computation path of the algorithm that leads to yes.
▪ 至少有一條路是對的
▪ If the correct answer is no, then all computation paths of the algorithm lead to no.
▪ 每一條路都是對的
Non-Deterministic-Vertex-Cover(G, k) set S = {}
for each vertex x of G
non-deterministically insert x to S if |S| > k
output no
if S is not a vertex cover output no
output yes
initial
configuration
30
polynomial
“solved” in non-deterministic polynomial time
= “verified” in polynomial time
▪
P ⊆ NP
▪
A problem solvable in polynomial time is verifiable in polynomial time as well
▪
Any NP problem can be solved in (deterministically) exponential time?
▪
Yes
▪
Any NP problem can be solved in (deterministically) polynomial time?
▪
Open problem
Why?
▪ http://www.claymath.org/millennium-problems
32
▪ Yang–Mills and Mass Gap
▪ Riemann Hypothesis
▪ P vs NP Problem
▪ Navier–Stokes Equation
▪ Hodge Conjecture
▪ Poincaré Conjecture (solved by Grigori Perelman)
▪ Birch and Swinnerton-Dyer Conjecture
Grigori Perelman
▪
Aug 2010 claimed a proof of P is not equal to NP.
34
▪ problems that are verifiable → solvable
▪ public-key cryptography will be broken
Widespread belief in P ≠ NP
“If P = NP, then the world would be a profoundly different place than we usually assume it to be. There would be no special value in “creative leaps,” no fundamental gap between solving a problem and recognizing the solution once it's found. Everyone who could appreciate a symphony would be Mozart; everyone who could follow a step-by-step argument would be Gauss...” – Scott Aaronson, MIT
36
Travelling Salesman (2012)
A movie about P = NP
Best Feature Film in Silicon Valley Film Festival 2012
37
38
▪ A problem is NP-hard if it is as least as hard as all NP problems.
▪ In other words, a problem X is NP-hard if the following condition holds:
▪ If X can be solved in (deterministic) polynomial time, then all NP problems can be solved in (deterministic) polynomial time.
▪ A problem is NP-complete if
▪ it is NP-hard and
▪ it is in NP.
▪ In other words, an NP-complete problem is one of the “hardest”
problems in the class NP.
▪ In other words, an NP-complete problem is a hardness representative problem of the class NP.
▪ Hardest in NP → solving one NPC can solve all NP problems (“complete”)
▪ It is wildly believed that NPC problems have no polynomial-time solution
→ good reference point to judge whether a problem is in P
▪ We can decide whether a problem is “too hard to solve” by showing it is as hard as an NPC problem
▪ Class P: class of problems that can be solved in
▪ Class NP: class of problems that can be verified in
▪ Class NP-hard: class of problems that are “at least as hard as all NP problems”
▪ Class NP-complete: class of problems in both NP and NP-hard
P ≠ NP P = NP 40
undecidable: no algorithm;
e.g. halting problem
https://www.youtube.com/watch?v=wGLQiHXHWNk
42
Course Website: http://ada.miulab.tw Email: ada-ta@csie.ntu.edu.tw
43
Important announcement will be sent to @ntu.edu.tw mailbox
& post to the course website