Pleae Complee Coure Survey CMPSCI : Inroducion o Algorihm Dealing wih NP-Compleene Dan Sheldon hp: //owl.oi.uma.edu/parner/coureevalsurvey/uma/ Univeriy of Maachue Slide Adaped from Kevin Wayne La Compiled: May, 207 Coping Wih NP-Compleene Approximaion Algorihm Suppoe you wan o olve an NP-complee problem? Wha hould you do? You can deign an algorihm o do all of he following:. Solve arbirary inance of he problem 2. Solve problem o opimaliy. Solve problem in polynomial ime Coping raegie. Deign algorihm for pecial cae of problem. Independen e in pah, ree. 2. Deign approximaion algorihm or heuriic. Today.. Deign algorihm ha may ake exponenial ime. No oday. ρ-approximaion algorihm Run in polynomial ime Solve arbirary inance of he problem Guaraneed o find a oluion wihin raio ρ of rue opimum Greedy Verex Cover Here i a 2-approximaion for Verex Cover: Pick an arbirary edge Take boh endpoin Delee all covered edge and repea Analyi Reul i a verex cover, oherwie here i an edge remaining Final reul correpond o a maching: no wo edge hare an endpoin. Suppoe he maching ha k edge. Then any cover ha ize a lea k, becaue i mu elec a lea one endpoin of every edge in he maching The eleced cover ha ize 2k a mo wice he ize of he opimal Knapack Problem n iem, weigh w i, value v i, oal capaciy W Goal: maximize oal value wihou exceeding capaciy iem value weigh 2 6 2 8 22 6 28 7 Knapack i NP-complee: Sube-Sum P Knapack We already aw a O(nW ) dynamic programming algorihm
Knapack Problem Dynamic Programming v2 Knapack Problem Approximaion Algorihm Definiion. OPT(i, v) = min weigh of a knapack for which we can obain a oluion of value v uing a ube of iem,..., i OPT(i, v) = min { OPT(i, v), w i + OPT(i, v v i ) } OPT(i, v) = 0 if v 0 OPT(0, v) = if v > 0 Running ime i O(nV ) where V i an upper bound on oal value, e.g. V = nv max No polynomial in inpu ize Polynomial if value are mall ineger Idea: round all value (up) o coarer uni and run dynamic programming algorihm iem value weigh 9,22 2,96,2 2 7,80,0 2,27,800 6 27,7,8 7 iem value weigh 2 6 2 8 22 6 28 7 The reul will never exceed he weigh capaciy, bu may loe ome value due o rounding error. Rounding Deail Analyi Le S = rounded DP oluion, S = opimal oluion We ll how ha S ge nearly a much value a S : Round o neare muliple of θ: v i = original value.,96,2 vi v i = θ = rounded value. 6,000,000 θ vi = value acually ued in DP. 6 θ v i v i i S i S v i i S round up S opimal for rounded value i S(v i + θ) rounding amoun θ i S v i + nθ ( + ɛ) i S v i The la inequaliy i rue if nθ ɛ i S v i. Se θ = ɛv max /n. Running Time A Real-World Applicaion Recall θ = ɛv max /n. Value of a ingle iem in rounded DP i: vi nvi = n θ ɛv max ɛ V = n 2 /ɛ i an upper bound on oal value Running ime i O(nV ) = O(n /ɛ) Theorem: For any ɛ > 0, he rounding algorihm compue a oluion whoe value i wihin a ( + ɛ) facor of he opimum in O(n /ɛ) ime. Fir, an exenion o he Knapack problem Suppoe here are k differen acion available for each iem (e.g., ype of repair o apply o infrarucure elemen) wij = co of acion j for iem i vij = value of acion j for iem i Sill O(nV ) OPT(i, v) = min j { wij + OPT(i, v v ij ) }
A Real-World Applicaion A Real-World Applicaion Now, uppoe he iem value are no independen, bu ordered from o n uch ha he value from {,..., i} depend on value from {,..., i } and acion aken a i OPT(i, v) = min j { wij + OPT(i, f ij (v)) } f ij (v) = value needed from {,..., i } o realize v uni of value, auming acion j aken, e.g.: wij = cah fee for invemen ype j fij (v) = aring accoun value needed o ge balance of v dollar in nex ime ep if ake acion j Sill O(nV ) Inerpreaion: OPT(i, v) = ROI curve. Can be exended furher, o cae where here i a rooed ree on iem Le T i be ubree rooed a i val(t i ) depend on {val(t l ) : l i a child of i}, acion a i Barrier-removal in river nework. Summary Topic Polynomial-ime reducion NP-compleene Nework flow Dynamic programming Divide-and-conquer MST Greedy Graph algorihm and definiion Aympoic analyi Polynomial Time Reducion We focu on deciion problem, e.g., for inpu (G, k), he queion i doe here exi a verex cover wih a mo k node. Given wo deciion problem X and Y, X P Y mean ha i poible o ranform an inpu I of X ino an inpu f(i) of Y in polynomial ime uch ha I i a ye inance of X iff f(i) i a ye inance of Y The ranformaion i a reducion from X o Y. We aw example uch a VerexCover P IndependenSe -SAT P IndependenSe Ueful propery: If X P Y and Y P Z hen X P Z. NP Compleene P = e of problem you can olve in polynomial ime, e.g., minimum panning ree, maching, flow, hore pah. NP = e of problem you can verify in he polynomial ime: If he anwer hould be ye hen here ome exra inpu (a wine or cerificae or hin ) ha you can be given ha make i eay (i.e., in poly ime) o check anwer i ye If he anwer hould be no" hen here doen uch an inpu. Y i NP -Complee if Y NP and X P Y X NP. Ueful Properie: Suppoe X P Y. Then If Y P hen X P. If Y NP and X i NP-complee hen Y i alo NP complee If Y P and X i NP-complee hen P = NP. NP -Complee problem are in ome ene he harde problem in NP. If you can olve one of hem in polynomial ime hen you prove P = NP. Bu very few people believe hi i poible. Nework Flow Flow nework Flow Direced graph Source node and arge node Edge capaciie c(e) 0 Capaciy Conrain: 0 f(e) c(e) on each edge Flow conervaion: for all v / {, }, f(e) = f(e) e ino v e ou of v Value v(f) of flow f = oal flow on edge leaving ource Max flow problem: find a flow of maximum value Reidual nework encode how you can change he curren flow wihou violaing he capaciy conrain. Ford Fulkeron Algorihm: Repeaedly increae he flow by finding augmening pah in he reidual nework.
Augmen Example Augmening Pah /6 2/2 /20 /6 2/2 /20 G / /9 7/7 G / /9 7/7 8/ / 8/ / / / 2 2 G f 7 G f 7 8 8 New Flow Max-Flow Min-Cu Theorem /6 2/2 9/20 G / 0/9 7/7 v(f) c(a, B) for any flow f and any - cu c(a, B) 2/ / 2 / 9 Upon erminaion, Ford-Fulkeron produce a flow f and cu (A, B) uch ha v(f) = c(a, B), o f i a max-flow and (A, B) i a min-cu The cu (A, B) i found by leing A = e of node reachable from in reidual graph G f 9 7 2 Dynamic Programming Deign echnique baed on recurion. Idenify recurive rucure by wriing recurrence for opimal value. The recurrence idenifie all ubproblem. Solve hem in a yemaic way aring from imple one fir (bae cae) Example: Weighed inerval cheduling OPT(j) = max{opt(j ), w j + OPT(p(j))} OPT(0) = 0 Compue OPT(j) ieraively for j = 0 o n Running ime O(n) Divide-And-Conquer Deign echnique: Ofen: divide inpu ino equal ized chunk, olve each recurively, combine o olve original problem Can be more uble e.g., ineger muliplicaion Tip: don hink abou wha happen inide recurion. Magic Solving recurrence, e.g., T (n) 2T (n/2) + O(n) Recurion ree, unrolling Gue and verify : proof by inducion Maer heorem Suppoe T (n) = at (n/b) + O(n d ). Then: O(n d ) if d > log b a T (n) = O(n d log n) if d = log b a O(n log b a ) if d < log b a
MST Greedy Algorihm Definiion: panning ree, MST, cu Cu propery: lighe edge acro any cu belong o every MST Prim algorihm: mainain a e S of explored node. Add cheape edge from S o V S. Repea. Krukal algorihm: conider edge in order of co. Add edge if i doe no creae a cycle. Greedy algorihm are hor ighed" algorihm ha ake each ep baed on wha look good in he hor erm. Example: Krukal Algorihm add lighe edge ha doen complee a cycle when building an MST. Example: When maximizing he number of non-overlapping TV how we alway added he how ha finihed earlie ou of he remaining how. Greedy Algorihm Thing o noe: If a greedy algorihm require fir oring he inpu, remember o include he running ime of oring in your overall analyi. Focu on correcne proof: greedy ay ahead, exchange argumen, inducion, conradicion Wha o know: Apply/adap proof echnique for cheduling problem; olve imilar problem Working knowledge of MST algorihm, Dijkra: apply o concree example, underand principle and proof echnique Relaed Traveral Algorihm Graph Algorihm: BFS and DFS Tree BFS from node : Pariion node ino layer L0 = {}, L, L 2, L... Li defined a neighbor of node in L i ha aren already in L 0 L... L i. Li i e of node a diance exacly i from Reurn ree T : for any edge (u, v) in graph, u and v are in ame layer or adjacen layer Can be ued o e wheher G i biparie, find hore pah from o DFS from node Reurn DFS ree T rooed a For any edge (u, v), u i an anceor of v in he ree or vice vera. Boh run in ime O(m + n) Boh can be ued o find conneced componen of graph, e wheher here i a pah from o Biparie, Direced Graph Algorihm ha grow a e S of explored node from aring node BFS (raveral): add all node v ha are neighbor of ome node u S. Repea. Dijkra (hore pah): add node v wih malle value of d(u) + l(u, v) for ome node u in S, where d(u) i diance from o u. Repea. Prim (MST): add node v wih malle value of c(u, v) where u S. Repea. An undireced graph G i biparie if i node can be colored red and blue uch ha no edge ha wo endpoin of he ame color G i biparie if and only if i doe no conain an odd cycle G i biparie if and only if, afer running BFS from any node, here i no edge beween wo node in he ame layer A direced graph i acyclic (a DAG) if here i no direced cycle There i no direced cycle if and only if here i a opological ordering. Can find a opological order uing he fac ha a DAG ha a node wih no incoming edge.
Aympoic Analyi Given wo poiive funcion f(n) and g(n): f(n) i O(g(n)) if any only if c 0, n0 0.. f(n) cg(n) for all n n 0 f(n) i Ω(g(n)) if and only if c 0, n0 0.. f(n) cg(n) for all n n 0 if and only if g(n) i O(f(n)) f(n) i Θ(g(n)) if and only if f(n) i O(g(n)) and f(n) i Ω(g(n)) Know how o apply definiion, compare funcion, ue o analyze running ime of algorihm