0% found this document useful (0 votes)
15 views14 pages

week 12_LectureNote_watermark

INTRODUCTION TO ANALYSIS

Uploaded by

SandhyaKastala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
15 views14 pages

week 12_LectureNote_watermark

INTRODUCTION TO ANALYSIS

Uploaded by

SandhyaKastala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 14
Week 12- Lecture Notes Topics ‘ dynamic Frog ramnuning - memoizetion avd subproblems - Fivonaeei ] examples - Svrortest paths . questing and DAG views Computational Complexity Dynamite Frog ramming (vp) * Big idea, herd, yet simple. * Powerful algorithmic design technique . Lorge class of seeminglyvexponential problems have @ poly nomial soléHon (“only”) vie dP. Farticularty Foroptimizotion problems (minlmen) - Enomple: Shortest poths. A dynamic Programming i¢ o consoled brute- fore methool. Tt uses recursion end re-use, D6 “controlled. brute- force” DP a “recursion and re-use” Fibonacci Alumbers Filoonacei numbers ave of the Porm 0. 6. 8, -Me, : hes F-5 Goal: Compute Fy Noive Algori ton follows vecursive definition. fib (mn). iP ngo return $2) 2 else veturn 4: fibln) +4ibln-2) => Thode TLnei) + Tla-a) A Olt) » A =e" % 2Tln-2) oll) y gre Exponential BAS! nN / Ga) /\ J Gq) O& a Memoized bd? Algorithm memo = {3 fiw): z iF nm is in memo: return memoln] 3. else: if neQ: fel 4. else fe Holn-D stibln-2) memo LnJs £ ‘. teturn + * $0 Lk) only yecurses Pest time called VK = onlynveememvized cells : Keh2,c0n e memoired cells free ( OliSime) * OW Hime per col Wgworing yeeursion) Polynomial - GOop\ © DP x “recursion Smemoizetion” © memoize. (vemember) and ve-use solutions to Subproblems +net help solve problem — in Fibonacci , subprovlems are fy Fay---1 Fr = ptime + # subproblems » Lime per Subproblem) +Fionecei + # subproblems =n. Hime pey subproblems Ol) a Hime = O(n) Uignoring vecursions ) Bottom-up dP Algoritam ' Hbe= Tf 2% for K im Lutyens 3 if K aes gel Bln) 4, else: Pe filo [ee] + fib le-27 | OL. 5 site) + F 6. Teturn fib tw) senactly the seme, computation ab memoized bP (recursion “unrotied ‘) cecumsion va ein general : tepelogical sort of sub problem dependency bag. . proctically jester: no secur sion : anely sis more olovious * Con save space: last afin > Ot) Shortest Paths + Recursive formulation Stun) emnin {uotv) + 5L6ud | tow) €€ J + Memoized DP algorithm : toked infinite Hme if cycles. (necessary to handle negative cycles) + Works for directed aeyelic glse) aphs iv ose) | ~(effectively v°5/ 5ts.09 topological gost + Gellman 1 Sls.) ford rolled into single recursion) $v) $lss) + Suloprotolem dependency Mould ve slo a Oeyclic « -more subproblems temove eyelie dependence SulSveNgvortest Sv path using & & edges ~ tecurrente? Selb) + min {Sur S0(S¥) = 0 for SHV | bose _ Sy (53) + 0 for amy " / aeeaee - goal » BU) = Sieg lv) iP no negative cyple e -—Mewoi ze ~time : # Subproblems - [¥ime per sulpzoblems) wiwt olv) 6 olv’) - actually 8 Uindeqree lw) jor Syl) =D>tme OVE indegree(a)) = OLVE) [4.u) avotuad | Ou) € J BEUMAN FoRS | Guessing How to design yecurrence ewart shortest Sov peth es whet is the last edge in path? den't Know s guess tt is (uv) path is shortest su poth + edge (uv) eee eee by opHmel substructure scott 18s isu) + uatuev) Ser Onother sulproblem, © to Find best quess, try all Cl choices) ond use best. o*key: small (pelymomial ) # possible quesses per Sub problem — typieally this dominates time] subproblem. * DP zx tecdRStOWeb memoi zation +quessing DAG view ~\ike replicating POs . graph to vepresent Hme ~ converting shortest He 2 peths in graph to shortest pots in BAG 7 "Dee shortest paths in some DAG Suen ary + DP & careful orute fore = quessing 4 vecursion + memoi cation = dividing into teasonolle y# suloproblems whose Solution relate - acyoliely - usually via questing ports of solution ctimes de suloproblems x [time per suproblem) —_ treating recursive calls os oli) Cusuelly wainly guessing ) - eosentially On amortization - Count each suloproblem only once ; ofter Pivst timey/costs OL) vie memoizetion “DP & Shortest pathy in some DAG. 5 aby steps to Dynomie Geograrmming define subproblems count 4 subproblems queee (pert of solytion) count + choices telate suloproblem selutions compute time per subproblem feturse + memoize problems Hme + lime per suloprobele) o X® suoprovlems uild DP table betom-up cheek subproblems acyclic |+epologicel order. Solve original problem: => extva time = 0 Subproblem oR by wunking oubproblem solutions. Enomples Fitoona cet Shortest paths Sulopro blems on &, (ov) for VEN, 0 KE IVI Jordhe KE vi 2 ming sv poth using £ Kedges #subproblems ” v* guess viothing edge Into Lif ony) ¥ choice® L indleq reel) +1 Teeurrence Fe Feat Fea Bld) = vain V5 re Us,u) + wl? He per Sulproblem Bw Coe Fl i. ols indegree(™) logical ee for Keli 9 for Keo, Wie) for vEV fotel Hme etm) oe ™ . +OlV) unless efficient ebout original ee ee prdolem Fn Sy to9) dor vev entra ime 6) pv) C omp utational Compleaity definitions: Ps {problems solvable in (nt) time J (polynomial) EXP: { problems soluable in oo") time } (eaponentia) ak . { problems solvable in Pinite tiene 3 “recursive” lee SS ? ‘onal difficulty ee exe we & uncomputalole /) P g EFS R undeadeble Examples: negative - weight cycles detection EP hess EERE wut ¢P whe wins fram given load canFiguration | Tetris ¢ EXP but don't Know whether € P survive given pieces Prom given tooard. Given a computer program does it ever halt Lstop) ? * uncomputable ( ¢R) + no algoritim solver it (correctly in Binite me on all inputs) * decision problem: answer is YES or NO Most Decision foblems are Uncomputable + program x binary string x nonnegative integer EA) s decision problem = @ function Prom binary strings (= non- veg. intergers) to [YESin, No lor} oz inbnite sequewe of bits = real number ER WI not nearly enough 78g yams fos all problems * ea0n program solves only one problem * => almost all problems cannot be solved NP NP: { Decision problems selveble in pelynowriel Hime via & \ucky alqoxttam} “The lucky algorithm con make . ” * e \ueky gueses, @lwoys right without trying oll options * nondeterministic model + a\qori thn makes gueses ond then says YES or NO * guesses queranteed to lead to YES outcome iP possible Example: Tetris ENP * nondetermini she algoritowm t quess each move, did 1 survive 1 + prooP oP Yes: Wot what moves to make (rules of Tetris are cosy ) AP NPs {decision problems with solubens Hat con be checked” iw polynomial, Hime} => when answer is YES, it con be proved, and polyromial -time algorithm con check proof. —_— computation 7. diffi culty ne Ve ae ee, Ungomputable / undedidatole R P#AP —— Ikie a big Genyecbure (worth 41,000,000) + zconnot enginee? luck . £ generating (preots of) solutions con be herder then checking them Hadness and completeness Claim: Tf PNP, then Tetris ENP P Pro? * Tetris is AP- hard = “es hard as” every problem ent Injoct . Tetris is AIP complete = NP i [NP-herd) NP- Ward a : Ex?- hard i _ Chess AP : ss Exe uncomputolde/ ba we undecidalole * Chess is CAP-tomplete = EXPN ExP-herd- ExP- hard is as hard as every protlem in GaP. TP NP # EXP, then Chess ¢ Ext\ne. Whether NP EXP ib also an open problem but less” Jomous /™ impo: Reductions Convert the problem into @ problem that i> already known Wow to solve | instead of solving Prom serateh) «© most Common algoritnun design technique + unweighted -shortest path > wei ghied (set weights) + min product path » shortest path [take 1095) * longest path + shortes path (megotive celea * shortest order four shortest path (x copies of the graph) + Cheapest leaky-tank path > Shortest path Pee 4 q (gre we teduchon) All of the aloove ave One-calli¥eductions: A problem ANB problem -+ Gsolubion — A solution Multcall seductionie: soove A using Free calls +> B, “in this "sense,every algorithwn reduces problem > modelo? computation ” N¢- Complete Problems NP- Complete problems ave ell interreducible usin Polynomial Hime teduchons (some difficulty) We can use reductions to prove NP-hardness Tetris. Ertamples of NP- Complete Peovolems « Knapsack ¢ 3- partition : given w integers, divide them into triples of equal sum? ° Travelling Selesmen Problem + ~ shortest path qhat visits all vertices fo oven, reyple is KL weight gal Pecision version) \ongest common “subsequence of Kk strings Mine sweeper, Soduku and most puzzles SAT : given @ Boolean jormula (end,or, not), is it ever true? ¢ Shortest paths amidst obstacles in SB * 3 coloring a given graph «Find largest clique in@ given q7eph-

You might also like