Notebook 231102
Notebook 231102
Syllabus
Greedy Algorithms
Dynamic Programming
NP-Completeness Theory
Approximation Algorithms
Computational Geometry
Streaming Algorithms
References
Scores
hw: 30%
bonus: 3~5%
Stable Matching
statement: given two equally sized sets, every element having a preference list of the
elements in the other set.
a pair (A,B) is unstable if both of them prefer each other to their current partner.
Proof: By contradiction, suppose (A, X) is an unstable pair. Assume currently A-Y, B-X,
then X > Y in A's list and A > B in X's. Since A's matching is Y, all previous girls must have
rejected A, and so does X. But when A proposes to X, X's current boyfriend must be not
better than B, so X cannot reject A, which leads to a contradiction.
trick: how to generate a random permutation. from to , every time randomly pick
one element in the remaining.
Theorem: .
G-S: each time a boy proposes to a random girl he has not proposed yet.
G-S': each time a boy proposes to a random girl. (possibly he has proposed yet)
BFS/DFS
Lec2
Parenthesis theorem: [discovery time, finishing time] in DFS do not intersect.
white-path THM: Consider the time DFS discovery M, V is a descendant of M (in DFS tree) iff
Proof: trivial.
Algorithm: Repeat selecting the available activity with earliest finishing time.
Optimality: Assume initially jobs are in arbitrary order, swap the neighboring two jobs if
their lateness forms an inversion, and the max lateness does not increase.
Example: Dijkstra Algorithm for shortest path
Algorithm: Maintaining a set whose shortest path has been determined, and every
time from all edge , choose one with minimal , and
append to .
Lec3
Minimal spanning tree for undirected graph
Heap sorting
https://en.m.wikipedia.org/wiki/Laplacian_matrix
Lec4
Greedy Algorithm (Cont'd)
Algorithm: evict the item that is needed the farthest into the future
Proof: First prove reduced unreduced. Next transform any non-ff schedule into the ff-
schedule, by showing if agrees with in first steps then that agrees with
in first steps and have same time of misses as .
Online version: LRU used. Bound of LRU: .
Algorithm:
Proof is by showing for every zero cycle , an optimal arborescence will have only one edge
entering , so contracting is WLOG
Tree-Matrix Theorem
Proof (?)
Goal: Given intervals with values, pick a subset of intervals that are mutually compatible and
maximize sum of values.
Algorithm: Sort intervals in ascending finishing time, let be the last interval finishing
before starts, be the answer considering only the first intervals, then
.
Subset sums: Find maximum subset sum that . Is a special case of knapsacks ( 背包).
The knapsacks algorithm is a pseudo-poly algorithm; It relies on the scale of volume, but poly
algo should only polynomially rely on the input size.
(Coherence) Let , , and be three nodes of such that lies on the path from
to . Then, if a node of belongs to both and , it also belongs to .
Coherence ensures that when we delete a node or edge in , correspondingly breaks
apart like a tree does. See AD Thm 10.13 (P575) & 10.14 (P577).
Lec5
Bellman-ford Algorithm (ItA 24.1)
An intuitive algorithm:
An elegant implementation:
Proof = Telescoping
Minor: A minor of G can be obtained by contracting edges and deletion of nodes or edges
from G.
Ex.
Robertson-Seymour Thm: every family of graphs that is closed under minors can be defined
by a finite set of forbidden minors.
Polynomial-time reduction
Def. Polynomial-time reduction: If a problem can be solved in poly-time plus an oracle
that solves problem (in O(1) time), we call is poly-time reducible to , denoted
.
Cook & Karp. If edges are defined by poly-time reduction, all problems in NP has path into
NPC, and within NPC, there is a complete graph.
Examples of NPC
Independent Set Problem: Given a graph , ask whether there is an independent set of size
at least .
Proof of : is an iff is a .
Definition of NP
Def. is the class of all problems for which there is an efficient verifier for .
NP-Completeness definition
1.
Cook-Levin Thm (1971): SAT is NPC. (SAT = Boolean satisfiability problem = Determining whether
there exists an assignment of truth values (true or false) to a set of Boolean variables that makes a
given Boolean formula true)
Lec6
Overview:
CIRCUIT-SAT: Given a boolean combinational circuit composed of AND, OR, and NOT gates, is
it satifiable?
It's NPC due to the workings of computer hardware (composed of circuits) (ItA Lemma
34.6)
CIRCUIT-SAT SAT, because we can assume every node in the circuit correspond to a
boolean; Then we take the AND of clauses of every nodes in the circuit together, with
the final node. So this boolean formula is satisfiable iff the original circuit is satisfiable.
(ItA Thm 34.9)
A 3-CNF is a CNF with each clause having exactly three distinct literals.
SAT 3-CNF-SAT. Proof: First we can use the method as above to construct the clause
tree of an SAT, every node of tree having 1 or 2 children. Then we obtain a formula
composed of conjuctions of clauses each having at most 3 literals, but not necessarily an
OR of them. Then for every clause, we bruteforcely enumerate over all possible
inputs, and use the 1-output tuples to rebuild an OR of AND clauses. Finally we apply
DeMorgan's laws to change it into an AND of OR clauses, i.e. a CNF. (ItA Thm 34.10)
CLIQUE: A clique is a subset of vertices that are pairwisely connected in . The CLIQUE
problem asks whether a graph contains a clique of size .
3-CNF-SAT CLIQUE. Proof: for a 3-CNF-SAT problem with clauses, we constuct a
graph with vertices, corresponding to every literal. Two literals are connected with
edges iff (1) They belong to different clauses (2) They are not complements, e.g. and
. Then the constructed having clique of size The SAT is satisfiable. (ItA Thm 34.11)
VERTEX-COVER: A subset of vertices that covers all edges. The problem asks whether a graph
contains a vertex cover of size or not.
HAM-CYCLE ?
TSP ?
SUBSET-SUM ?
3-matching: ?
3-color: ?
Lec7
NP-completeness: decision problem
We want to further define the set of problems that we can polynomially solve, this can be
done by parametrization.
Def. FPT (fixed parameter tractable) Let the input size of a problem be and we have a
parameter , we say a problem is FPT if there is an algo that solves the problem in
time. e.g. is feasible but is not.
We revisit the vertex cover problem, the parameter being the size of vc.
ALGO check(G, k)
if G has no edge, the empty set is a VC, return T
if |E(G)| > k|V| (the maximum number of edges coverable by k vertices),
return F
randomly pick an edge e = (u, v),
return check(G - u, k - 1) OR check(G - v, k - 1)
Best FPT:
Kernel method:
Problem statement: Given a set of machines and a set of jobs, each job
has processing time . We want to assign the jobs to the machines such that the max load of
machines is minimized, formally, if denotes the set of jobs assigned to machine
then machine 's load is and we want to minimize .
Another approach is using subset sum. Subset sum is , and if load balancing is
solved then giving two machines and asking the minimal of maximal
load to be will resolve the subset sum for with target .
A greedy algorithm: Process the jobs in any order, one by one. Assign the job to the machine
with then minimum load.
Assume the machine with largest load is . Consider the last time we assign to
then and .
Worst case of the greedy algorithm: we have jobs of time and one job of time
.
An improvement of the greedy algorithm: we do not process in arbitrary order, but in
decreasing order.
Proof: Similarly assume the machine with maxload is . If only has one job then
our answer is optimal. Else let be the last job assigned to , then , and
thus .
S = G, C = \emptyset
while (S <> \emptyset)
Choose an arbitrary vertex v \in S, C <- C + {v}
Remove all node u s.t. d(u, v) <= 2r
If |C| > k, our guess is too small.
If |C| <= k, succeed.
Define the Promise Problem: for a given input, we guarantee the optimal value is not in
, ask whether the optimal value is or .
Then an -approximate algo can be used to solve the above promise problem.