0% found this document useful (0 votes)
261 views

1) Algorithm Notes Made

Algorithm

Uploaded by

Bibin Raj B S
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)
261 views

1) Algorithm Notes Made

Algorithm

Uploaded by

Bibin Raj B S
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/ 87
| Deoint Set data sbuuethue: maritawy a cotteelion 8+ $5.5. Se3 ef chyyeint dynamur Sets Each tO calentyfeed by co copuesentituuia € Set. 4 a> reprsscnblus cb,eo! non per ations suppoled ons | NAKE_seTO). creates @ neto set tutth only cmember , hence M bhep Sones dliyoint x cxumk be wr any olhus sel- UNLON OUD: nck dynannus sett conteuneny Handy . Sand 4 (® One Se fescue 2 Sut aus dleyecnt prior & uncer . Rep € SyUSy twe destroy Sx and Sy. Fin) Ser Od: Roliuns a pont o raprosorlitinn of unujue et contauneng % Running tre of diyount dato su ds analysed! using 2 powosmeter Mm mo. of MALE. 67 opeLaliim m= Toto cno. 64 MAkeSer + UNloW+ FIND.SET Atanost m-1 mo of unico sporations | | Application of djoint data -stsurctuer — Deturmaring Comnintid Component 6 indict pcph Comncelid - Component (e1) Samu -Compoment (u,v) [ot each uclta ve Gv i Fino. Ser (U) == FIND-SeT(v) Mate Set (v) Releun TRUE fo* ecueh edie (urv) € QE else Reliun Fase | If Fist d_se7 Cu) # Find-seT (Vv) | UNLON (2t,V) Conneeléd - componen’ - Uses duycunt set epecaltons & compute Conneclid Components ef 0 Graph Sanne. Compoments - Anscuus cohether & weller au ww tanne Cenneclid ampnt Connselid Components - Place each cwerlex & wb own sels. For cach edge Cov unels gels contacting Uondy. Apia proousing UW edger, 8 galt UM GAM Conreclid osmparent: tf Uney belong b game sek AT Indeadcols | $3 $63 $c? fo? %2 WR §y% fh? Ge? T7? Falges proewsol ab) — | fan? $3 a3 Sed SEE Fy? tae SP EP (4,0) Sorbet ‘d 4 S, cap $62 173 (ho) farb,c? fat get gt ‘ gar fk 02 (a) | Sa.b,car fer et) int 192 (op fehgh the he yw) fhe} 43 Result chews 4 connected cemmpenens Saybcd3 F6F 93 gh? 7 Lembuol Lt Reprasentateom of dtygant els Foch ae & tapeuenteet by ts own Undid Let Chyck ejpcach set hos aliabeeles hood : pio [ost object on tut Toul: pt to tout object wm luk Foeh obfcot on et lst conlaun @ set rnamber, a point to nent obpect lit _Deaurion Remaindus, Hedule Egeucretone: ¢ ane pimultyls of 0 Seucn an tnlegar m1, (nleges can he parttenad inte K mem. meltiplis of 7 Nom anuellepls of 7 can be alarsifeed & por rermaundes fehin diva tel by 7 Theoxermr Fou any entiger a, ancl rue enteger , there cru Unegtu ranlegan gare: S$ OSKeM and a=gnth gz arn w quotient ef clrauscen {= aomod m tenatnder o Aosicus of chau buen nla tf amodn=o > Woe con paxtiion Uinigus tanto on eguutucrlance classes according fe ther Mismas modelo m Fqueuatanct claves only an intiges (0) ,= Satkn kez} ‘9 (1, = 74,3,10,1F,- = a€lbln = 2=banodn Comomen Drutsor and GCD yaa disor of 0, d dreusor of b, theo d 0 Comme drrcuot ef a and b Drausor 6 80 = 1,243,516, l0s1S, 30 y= 11213, 4,6, 8112, 2y Coamanen iausat of 30 and 24 = 1/213,6 ty of Comanan olinisor Alaand Afb cmplus djorb anc dab famplu djax by gor any milage x and y | pal ther eh a.4b a bo | olband bla empl a= tb | geo: ‘paand baw 2 on-gew cmlegos (hen Geo Far 6) an canteger fast ctnel emu Prope of Gen Geo (Orb) = Geo( ba) Gen Com) = Gen Carb) Qcp (4b) = 9¢0 Clo 1b) Geo Cao) = 1a) co (0,ka) = lal Jrany kez Theewem:) J aand 6 au any enlegeu, nol beth 200, then qer(@s) @ the Smaltal tue elemen & Sebo Forsby xy eX? of laces combinatuonsa], acne 6 Im- Io any conlegus acad b, ¢ dla ane dfb then Af Gc0 (o/b) ged (am, bn)= gen (arb) A nlabandssrhs gen (and=1, then nb | 4 4cD(Orp)= 1 Ge (bi p) = then Yen Cab, p)=! Drewacbiluty by preames : Fo aU puemes p, att ntegou aand 6, plab then pla a ‘plb o% beth nag Sactougateen | Thou o exactly on way bo wk any comport entger a as a product of fou a =p pe pt thou pea purms —pkpa-- Pr pe. pe & “pl pitt. pf eoeth guo exponents the primar of & els becorne egal geo arb) = piMA(@nF pmo Cerfe) mae fo co Algouthan | Qcb Rapousstin Sheotorn Q= be amy mon negate tinleges be be amy posthow tnleqer Geo (arb) = Geb (bs ammod b) Eeuclecls dlgoncthon : Euet.ro (01 b) ipb==0 Run a — jf qco(aro) = lal- etse Retun Qco(b,amodd) QCD (30, 9 Eucttn (30; 21) | bso 1b-21,b40 Relun a. © elie Retain (B, amod 5) b amd 6 a go med ar2 149 247 q amd qs 2943 =3 3 qmod 3 = 0 “2 Geo (0,9) = lal hurning Dans of Kuckiols aleym Reennig lms ef Euclid algm o& mo of Ksceurs(ue calls iomake kxtended kucbolean Algouthan: Woe extind kuch algm b foro emagu coefficeants wand Y d= gww(arb) > axtby Hand Y amay be eo rue The cweffeoun au cstfeul for gellene moclerlax anuttsplicetuns (euise Proceduue takes & erpuls arb - non egaten cnuages tollun Lips @.4) | | keclanolecl — Euclial (a, b) | b==0 Retun Cayt10) | else Cdia's d= Extandleal. Fuckal (b, amod b) « (dynryd = (@x/y’- Lafb]y’) Return C1 Y) | No: of kuceuursire calls mode tn Ectch.o = No.of xeccustur calls 9 Rxlendlecl.£ucle Running terns ef Euchiol and Extended -tuchd aw sams For as 6»o the ao. 6f tecourcas calle w O( gb) PRIMALITY TESTING Rex fendteng fauge peeames Density of prcane Nos Prome Dalivbullon Fencltin Tn) = No of prumss Nl) = 2,3,7,5 Reto) = 4 lop hein o« equal (om paces Mo. Theorem. fam Ken), N3O N/Inn coowals estimate of TOM eusn for Small Approugnatum n/tan qos £9: ta of by lus than 6% at az tot Hn) > SO8G7S34 Random corteger 2, be puters, by prune no» -thoprerm probability hat na paces u Winn le Expeclio No. 4 buals > Inn Taal diawiwen m be any odd tbege Than sppusentid as N= pe” po pe why AdI PrePr- por Pracrts forckous of % mo pun i an only ( kop nd er =l Dauotse n with cach ealeges 2,3--.Vn nu puns ff ao ual dirusou Areole tach bual diauain taku constant tema, Dost cow vumny dn OUR). quod draugean leliconunts % & presme Cr dompostls «nu composi - clatuanines ono of a's pune faclu Preuclo primalty Tuteig Jo'= non yuo olanmanls of Zo Zot e$ij2,.-- 2. if aa pumie Zot = xn Kano Compos Ue tat Say m 4 a base-g pscudepurms and a”! = med Fesmatl Jheorem lanplus that of 0 u prim, then sateyus a” = Lemed foe euny a € tnt jac mr", adeunct cabsty Female Ihcoutm o dsfeneldy Compost: Pskcpopein € (r) ry Hodulas-kxponcelialeen Ont, n) x 1med ne heluun coanposé dycnele Else Rettun putme- — cue exepeet Hodtutor. txpomenteabten (Or by 7) Ceo d=! ket benny kepacscr tanleen & b= 1andm ocd 2) bos Nooutak. ExPoNewr(Ar ion (4, m,n) 3) fon t= tok 9 be bevmnod 5) th e== Fond bey FI and bit FNL ; Rebun TREE dh Met! 3 Reload TRUE Q Relun FAuc- =D ers kan Bronony hap of n-1 = Bincuy up oj ™m fottoued by k 340. a" = tana m att = (a™)2* meal m a™! anod m can be computed by Compaleng a™modn * Thon Squaaung Ayala times Squoung done 6m Slips 3-6 Loop may Crmrumate carly £6 cletoverins mont keruical 99 tase set Aigm Stops andl keltnn ture | Up vortnen Gime TRUE from tens & then Xe = O™ onc #3 Mm Cannot be puss 5 per Jeumaks thm Fnalyse bohauwr of welows 0 feunctten of 8eq X= thou d #41 28eq ends tn | anel laut non #-! Lins & Ratuen Cur Q cattren M- Os de non leads Mpeau Kart oli Hellu-kaben(n,) & foyer Os 2 Gz Random(t, 2-0 3 th wilnen (a4) 4 ReLiuen Compostle s- Reltun pumi : Mo. No: nwa sci N= i m- m= odd compostl fo 20} ttle b> cumpostlinen of alleast 1-1 Jor any odd tage m +2 and teu tnlege S , phlly Melerrabue (+s) eno & alomoct 37S INTEGER FACTORI ZN TIOA Iningun & he dlecomnpereal tale pacducl mp pres Tual dhauston by intigqus ph Rk quanntn compels faaletrjalie of ang no Up R% Polfaid.Pho fora om. apo bY Poltaud- Phow hewule tw sanneny Mums on Socesu not qaanenlosd Pollard Rho uses only Constant ny of ‘ml (ocaltons Polenra—Ruo(n) total 2. X= Random (0,11) 3 Ym 4, b=2 S whule Teue é C= c4 7 WM =(42 -1) med n- 8 d = Yel y-ai sn) a BO4#! ond dyn lo punt cb u iteek la- Yur B be 2k Bowdeung : t Ina Gt 2 Random nw. usm Zn, tchule Coop og S Secunhu for prteu of w daung each dval of whb loop G) teortusu 9 = 2 mod n prodacts curt aol of % cn 00 Seq, 2, 13, Ly - - Poltard Rho orem punk mncotseel anscuer - Expeok joclor poh n afGu OCSP? elsral of whele oop th cornpesls O(n"). Hopute- I Que alst Common Diaucsor Py prime Foc tous atcom ~ geolay, reo) &b to aN ZN wo «68 a2 42 4\ IN ZN 2 ¢ 2 F 2 Ql ZN 7™. 3 s 7 | Rag aigts. > 93° =| (168, 1860) 16k Oe | ra \ lo 126 An JN 7N 7 ro ag a2 | A | a a \y 1 fs é™ 3 27 DBS 2 s Ye a4 D> eT ~| Gs 182,266) | 35 (82 266 7S / \ “N s 7 29 4 2 2 | 7~ “~ | 7 B 7 4 o7 2712 any PH Geo using Euclrotean Alam: Bass of Ructécloan dlgm > The Geo of tuto nalinel ros te ¢ame ou the gco ef Small maltial no and the ciffeence f 2 matwual cos Fg (tt0,970) => (tg0, 90) (2, 90) 9, 0) Geo (10, 270) = 20. - Glbef (8,84 = «2 | (180, 86) (84, t80) feo = Bey #12 | | C84, %) (29,12) By = Paina d | ar 12) (1a 0): | Cla, 7) | (la, 60) | (1a, 48) | Cras 36) | Cla, du) | (a, 1) be Des Reman Ua, BOe AXIS TLE ~~ 330,156 be FD | ka72, 166) (830, (56) ° feet 2 IR | tS & = ise, 1a = 2xb+0 < Stop Cte, 1a) = (1a, 6) (6,0) Geo of 330 and 186 =6 Rowe (8323, 654) 932%» 3xb54 + 360 (6sy » 360) bg =" x360 4 Bay Goo, 294) 30 IX 244 + 66 (2ay, 66) 2Au = 4X66 F 30 (66,30) bb + 2x80 +6 Gort) 30 * SKB FO (bs oY - | (2322, 6sy) | | (4322, 650) =6 | EXTENDED EUCLIDEAN ALGORITHM: geo= brot cyo 4 Geo of 42823, 6409 Diuudlia- = 42823 , 6404) 42623 = (6409, 4364) 6404 = (4364, 2040) A364 i (&by01 289) R0u0 = (397, 14) act > (1%; 0) Geo € 428236409) = IF | 4agaaa+ 6409 y = IF t ee AE | fa 42823 ¢ ° 6 6409 © 1 t 4369 "7° a ayo °" 3 ¥ Bq a" ” 4 i lg Couls —Dirusor Remaundx 6X 6y09 t 9369 1X 4369 + do4o = 2X w4O t IEF = 7K QF 4 UF = Irxly +0 C ° 1 6409 ob) 4369 a 2040 ¥ 284 be.” es Tk. at Alas n-ad + YOY XIV = 17 40803 = 6» 6YOF+ 4369 1, 4369 + 2opo 2+ 2040+ 289 1: 9894 (F ty TF FO Dnudint Bint Biauna — Kermaynd BRAT F OSUY = 6 329 © 3x 654 4 360 654 = 1 360 4 294 360 © 1x 244 14 66 2qy = 4x66 7 30 66 = 2x30 46 go 2 5x6 40 | ¢ Qt ae we er 4 A322 ° | oO 8 64 ° ‘ ly t 3600072 Da I 244 og! | 3 4 66 git i ' ge yan 5 5 6 a0” ~>) 8389 X20 4 6SYX-F = 6 LUY TESTING Peame Destribultom dinetion XCM © Mo Of primes that au Len than 0 equal le i n KO) = 4, 9,987 | Preemie mw theoscom tron 0 | a3 7 Inn | m/ Ina ~ geus aeasomarbly aeoeircate uslmates 6} XH) euen er smalln | Preecdo px ng: we Thut Daw'scon j eas opaimality Tating @ facg Bid ing | nt» Non Zero elements of %o mm: pi pat. poe | + $a, MIF tay cururtting » oath 23 wa | fh mo prune, An's Zr® ates prerme iff Mo dderessor clude nr Tums = @() | Feumab dheowam if on prone "= Heda) for euny a. Zr" a” a"! g 1(mod n) tun ma composite Pacuclopneame Cn) Ly Hoduteu.. Expomenteatton C2, nin) # | Gre ™ ; 9. Rolurn Com postle H Defonttely 8 Roe Actin parm A most probably Cemmechol oto ane comperult by Sebify 4 “1 nol W Sot, OS, 1729 | Eg Tost eahothee (9 parame o aot Proudo prams 09) 1 Molec Exponente alee 9!8 mod (9 == tonod (7 (2, 18/9) gl i¢onod 19) RERIGY nod | =I. t = tamed (4 pep. & Aopeftelty prone. MILLER: RABIN TEST: Based on Baste Princip a? = y?anod n) bul a ft ylomodn) The mu compocde General atlgont than 2) Find n-1 = okm D chome AS 1Ladn-t a from 2b n-2 YD Compute bo = a™cmod n) , be=(b-}* kg: | S61 paume 2 Till bg 2 lamed ° N= S6l° BER. Mt 580 2 860 i ZN Sco aac key ane 3S 2 140 aN | Qi Magar 2 TO ZN, | ' INTEGER FACTORIZATION: ~ Preme ‘actracgatton of 60 ‘30 2 = 2-3-5 PX: | - not | check 4or & pruane oF N= ho} N-1= AOl-! = 400 100. | ms 2m = ot05 ra | keh meas 2 owe - wt | Sekek 1acn a Se a=2. 2s. | bo = o™camod ) Zé | as, = 2° (mod 4o0) a: 93554422 - Base. = 32 Mod 400 oo bi = bo®= 29? = PAY anvd Goo ory . a = 82y vee be = bj? 2 Goze. = SOl76 amod yoo $0176 = tQeK YOOH | | | 2 ING ba 2 176? anod yoo = 30976 Md yoo — 30976> 77Xyoo-t7% | = 176. | 64 = 176? aed Yoo -. = Toledo of factors : Of 200 2 £ 200 as prime Bee pe 4 prions factors oe ate 2 Se Pane ae - cb) 25 Aloz (Qt, | PAN 4 pe 4x3 +12 fockw No t 2. be Sie Ge 03 9 asF) A%Sle AMA Qe- 2% 1 a allio ate fey 2% M20 7%"t00 a 2% ayo 200° ~ How aneny total factou for 24760 - "2,2 Py? AS 3 -u a 737s Total faclou = 2xqx3x2 | Ss (247 = 4 | 7X a | S445 7™ s A \ | 3 32 7 \ a - How anany feectou for 254528 | 254528 aN 2 127264 aN 2 63632 N 2 Bits N ' 1asy coe 2 17908 y \ 2 627204 2 ae 2” 33632 2 %3977 27 S15 6616 N zg *76yo? oP Naaz0p ota" u? x Syeoe Totes foctoes = @XSX2 & Geol = lao a N69 1 37 S363 x Yr ~ Hood many drausceu of 166 cw euen aN etsy oh Bute = 2B 2 G2 , 2t SN v3 — Wow mang dacion of 9160 an gnultipla of 2 pe Z “logo \ 2 Sue ola?s Zz 270 (ann) 3D 36 Gx 3x2 = 30 aN 3 Ge | ZN | L™ i™s Total mo of prumu dluwiot « 2 (2, 9,5) Prcoposlean of pli = sed Module FAOW NETWORKS aad FLOWS: A flow metwork QCvie) BO duscled graph ) whith each edge (uve E “hows anon. mega capactly ecu) 0 | Give & thon thew u mo eeaeue dag (Vu) B Gvyg & then cluv)=o Sey, lecps Qu mot allouecl _ pScuree (8) Flow nw has 2 uertiew / \ sent ® Each uartir Luson goomepath fiom $ &E Gms verst for each worlee of G / Graph & connceled os each cerlix otha than sounct fas an entkteng edlge JE[> Wier A flow 1 Qlvye) with capacly furclun cua acal valued funclten fivav—> R Satispe 2 puopeten D Copacudy Conmbaint = Fos au uveV uu wequae oefturv) ¢ evivy | Flow tmough edlge £ capacity theouph that celge |) Flow cusermmalen = Fora we V-$s,e2 we xequis = ftw = S_ Af iF ey fo when (4,0) 7 E ro floc frm ubv and Cluv)> law) =0- | ne flow prom auenter fo v - fowu)- atom egaliee quantity uctlo (C1 = Zhe 2 CH) : | = Total [low out of Sle- Flour wo Sc. Copacely Conshaint = Floco from one rweter & anothy anust bc rem negalui and anust ot exceed the gran Capacity Flow Consecalton = Total flow ub a werlex othe and Sie and Simk amust equal Eotal flow cet of euuiter “ Flovotm = Floco out". Fg: Od Company / Copacely ef popes grrisa wr gations 3 OO + > ww os & Y 4 50) +) 2 Randernly Choose @ path - Auganenlad path Ga-ct : Botttcauck - Nem Copacely of edge a the path O32 gp3c2t » MHD =? Rermaw the Saliualed edges and sedan wilh Kerndcoug | acty edt . Cupacty ee) wy, -@ C2p2AZE NA (2 23) 22 yo ay ea Statdtle - Ha (u,027 Total flow = 24241 = S- 6-0 les fcluval Graph oO \ 3 © Seer Max Flow ui a Flow milansks by Choosing path sandomty FeRp-Flureesen MerHea Chavdeal njw, Augmenting Pal Ctr’, Ficw Netwrcek GUO a ducelid graph Clu,v) € E Copacely Cw) do Cue & then Cv, uw) Ge le No Reus Edge Wcuvige thon Clav)=0- No Sel leops allouce Seuuees and Sink & Requus Capacity Censioent —> Of Fos € clu) Flew conseruclm —>& Flu,u) = Zz, fo Flow en = Flow out veV = EFS) M= 25 FC > Feud-Fulkuson. Melted (G,s,6) & Snelratize Low f <0 9. when thar 2xub an augmenting path po the resicluc nyus Gp z Augment flew { aleng p a etwas ‘d Resxcdual Ketuocu coy: cut f & only 0 used Wes 4 lye behead $ & Ruidual + Sanh canbe pumped Mrs 5 “oe fi .) WS Conceltateoer- Pushaeng flew om Rewwe telge on Residual oy Coredtakum ards cn cleowasing- deewasing the tualue tohich aluacy transmitted kesiclual mo GF Her we can find an augmentay path a sev 4y,5 6 Hun (5.4.5) = 4 Botluncek Ruicual capacdy 4 yn -@ nf AW WO c She “A / ™ ~ | A mPa dn © - “yf / x mtiuok g anda The socdual afu Ge - hes eclge wth oo that ort ha a can change the Pan on edged 9: Edge of flew yd can aden ertia amd of flow = Capauty - Flew on that edge (pe woleu - place that edge Gf - Gn adanet exha flow | & gs cohow feow equals copacely au nol w OF Goal of atgm a cneease folal flow, foe that ameg! flow on peuliculas ectgu Deeneaue of flaty xepresenuel as fluyv) on an edlgein G ~ planes edge (yu) | tnlo of exth Ruelual capacity GCirw) = fia) | Runuse talge allows tend What which how aleady ent though | Sendng flow back aleng an edge = beccauing flew on the edge | he Acue Go decrcaw | flows far G: (HE) wetth sewer s cand! senb €. | kel f he 0 flow & G and Cmuicler pai ef cuihésr ave V Reicleeal capacity cf (uv) a dined by Clu) - Flu) CUrmek CRO =F Bewjuy ymwee 0 othawt e A flow mo GWE) and a flows, the aucdual mw of G (neluced ty fu © Gp= (Ep) tahoe p= f (ayy) € VxV cf Cu wr0o?, | Fach eclge of tecolual apo o called Reseclecc ext ge Kelgu wi Ef ons elthor eclges on & or thon Keweeuats and thas lef] € 2/e/ ‘y fz aflow og fiza flow w correrpondeng wesc Mod Gp. | Te augerentalon of flow f byl» POY" x fr viw—> R difinuel by . feat fCuv)— flu) tp Cumee | arpa -[ ree othuwie . | Pushing flocd on keuurse tage eo Ure eercetaual a) calteet Cancellation Augmentation Paths : A flow ato Glue) and a flow fF, an cugeenting path p 6 a srrmplr path frum Sit & wales aw OF | Woe anay enoranse (Me flow of on eolge Cuyv) ef an auganenting path by Upto | ¢Curv) tetthout wolaking the capaccby eonskaint on ushicheuu (ury) o Uw) | & in exegenal flow alo Y / | Haxtancem ait by which we can browase the flow on each edge wan | Cugmmenting path p tte Residual capeecily | OF tp) = mein FCpCurw) + Cary) w on p} Foud. Fulkuson Repraledly augenent plow along a. le ths eentel tt has found a Histon fos ' BPG Mow Flow Mio Cut Theorem tells ux thak floo ue anaaccrneem Gy h tevduas Nw Contaios no augomentuig path HAX- FLOW _NIN- CUT THEOREM (faa flow m metwork glue) ath comets and sink E Fe touting conditions ae eguiratent t AG a amaxemum flow mg | & Rurclual mw Gf hes mo aug menting path ~ Ele ep | Cols wo Flow Nelurorh: 3. Rl CC 8,7) fos Somme cut 49 | Dude the wtienr bo & pols — one wut hou Souer other Well haus sme Iga "out SF SW pve} Te $¥5, vy 62 HS) == = fy -& Zflwu) ues veT ues VET Metftoeo acws cur ¢= fev, vs) + f (v2, vu) ~ £03, V2) © 1Q4-4 4 Copauly ef cur « Euugtrerg that od gotng fiom Socun Sede CCH = & EF Clu) ues ver = CC V2) + CCV2,Vy) = l24ly . = Ob Remioluclcowpacdly > y FoldFultevon says - when thas u an augmenting path , beep on addurg the auiolual Copaculy t you flow- Chow any path Bay SV v3- Wo- w-& 4lo ov 7 aC ; Choose path S-V2-Vy~ v3-E ate o> Nat x py wo iy ala ja G9 ay Flows fer? Nopath powrble Totaicopa ely was = loHs+ 29 Tolel {low = I2t = 22 Smt > 23 | Hax Flow fem 3a | Anatyss of Foudl_Fulkuson | dnitiolize flowf< 0 ole) [2 While thew ous augenentirg path th rundual gph (2 Mugment loco f clog p > Excouka nar of f bre 4 Reluun § oleit ) tot f be the nactaneem flow of the crelunsk a Finding path * graph Ceuthe tue depih fout Qearck / Beadth Foal) oft | tm kucducl graph mo. of edges unl be cleceasing and amaxcincum posschl yal a E- So Total Complaxcly : O(kIp)- A floro_retwork for whack Jord futkuson tars oftelep) tris ot : a 0 AE 00 a z oom o7| W gam | che & [2 i fom po? —__ 10°? ® we?) OW 09 ea é 9 “|, Te ao ph QO n GO ax Oo op od bo <]i08 “rom s Altinaloely S-av-b , 6-y-u-t petths 80 d wor take total af 20000 mos { diate Tot (cme cemplecety » OC It f) - Network avith ante’ parce : anaks tha a eenglt Sle , dongle seme pom. Apply a supeorser and supersionk and cclges connecting thea ausith enfinile capacity. Began Ford _Fitkeson (0,1 6) I fou each ectge (urd) € Ge 2 Uiv-feo 3 While thou exua a path Pp from Sit om Apseclunl ajw OF 4 (p= min § Cpu): Cv) O ww pi? fe each edge (uy; y) tp 4 (uw €& & 6 \¥ Cuvyef = rv -f tof lp) e else Cv,u)-f = DwW-F- FP Fdemonds. teup. AMgorthom (ast) Begen Inctealize flow fo tack there exests o Shortest augmenting path pir the xescoleeal neliuoik Gf clo Gugment flowf along p end End. ~ then Selteleng shoulut path, cach edge Considered cs hang tenel euerghe Edemond kaup aun on O( ye?) alporithen , OLE) or brs + O(ve) mus Kum . = 0(ve?) lolal oo ®) a (y gt fr fee £192 - Soe ge? yy af Ale ae 0 Ae | & ie: b folra b ~—é A “ee % jit 7 t iY 1, a fio My Gy ‘lo onone aucmentsig path, Hax pu 2 2 = S440 I wong Edmonds teup for — lamprourd ual Jclhurs ; gecuch Jor fencing the a aunly nal bel jan awying Breadth just wt Db tooo WO”? Snee shortut path ,clueclly feous (000, aud through next Shortut path anothur flow of L000. So If] = lwoo7 tovo = 2000 Puse- RELABEL ALGoRITHT Rens uv OC) lume » - Wok m one cater al a tm, looking only at ats mnerg hows on teclucl of ~ Donot maintain flow tosenaltom through out exccelun ~Mauntarn payftows — a jth fvav— oR thet sabuifeis Capercety eons yt ond following relaxation ef flow ceniernatun Ff ifm Ao forall aunties we V- $9? & low tntd dony aurtex may ented Che flow cut The Quardity eu) = = flyw— 2 flu & Colled Br cey fluo vev ve The exces at a cuntex v the armount by which flow & ereeels floes wel- A ueler Ue V-§ot2 o Cuceflourng 4 ecu) >O- When ecuy=o0 then Ut & flow- Funny node hos heghtr: Somer hught - lv! Arty hi(gink ) =O A othu auntecu heught slart arth o and Pees and tes AWW) 20 for euny node, o> Suuerping prouurdles con adeeng of geemelive ehjecki, by placing orm @ a dynarmis data shiuctue Tuy te fond out 0 plot whew one ox senna shings/pallve au found unth | a larger stung ort: | | RABIN CARP ALGORUTHN (Foe shin matching j= geuun a text Tand a patun, hows lv fond whether patlun ox ch the | txt © Preprocusscang fext pats « | ceagcols th cour ot haus tharabes auith aust membu | Ee F011 2/314 546,71 8193 Each characte u a deetonal diget | Go, de con usin or sbung of & digtlt a4 d decconal m0 unth length b | kg wt home 0 bl of 022467898 213556. pallun 7898 7e9e a a substuing of the text and abo 189 & a deerinal no of slengt 4. Go a abung hoy ancons 0 segerenes of chenacley G& E> fa...2,4,.. 22 Rader d notatwn, d= 12] Tolat ro of chacachis - $2 doe will consider Rewolix of = $2 So will get mos pb 82 cousponding & character Radlte S2 Numba sister « em ployeot to Seach TPE un 0224678 G82! 3556 Tabs 0 uximdowo of ualur (Length) = Length of palluw fiw @ eatinclowo of Size y 4 Faker and onatched 022467948 214556 ao) cleeconal no, 7989 match but hawe b make algonttien offectent | dual coltxpattatcon of syanbot -aembu ot employed Grown PLi.. me] bet p= decvamal evalue / pattern | TEI MI] tat by 2 cleceimat cater of 1 [5+1, 842, ... $400] fou [Text Sz O1,9,3. -Nm =p yy lst, 617, -. sim] = PL.-m] ([Setbshang 8% a uated shyt y ts

Blam) Genie ccheu on Length of paltun/ 0. of element (0 the patiun Compallt ts Coubsheig) wales co O(n-on41) tims | Compass elt exes shifts Been) + Bcm-oner) ~ Gln) lems by Compowing p with ab to (G= 0... meomer by using Hous Ru ual of Pa compared: How Ruel Euccluats ole of & polynoanil Pe planJs to PLon-1] + to( Plm-2]4-- 4 to(Ploq+ toPcq)-- )) | Enanple Geauen Po; 32731 | > Bxtolt 2x (024 TRIO 3xt0 +1 i No of cmutlyplrceclow 2 4434+! = © mullylicatw | Ato of onllipleratooms cen be hecluccel by i pulling % = (0 | © 3444 9484 7224 BXdE : 1 (3U212KEF TRASH | > a (1 (32249447)43) #1 | : a(n (9 (3x42) 44941 —_— tI 4 No: of omaltplicateons = g — 9m) cm) € ; Stnilaaty we con fond a sehshiing wrth los a ts a asincow of StK am: tsvr = tolts— 0" r[ser] + TE saan] Fg. m=. 623456246 ts: YS6 29 tse = Se2a¢ fsars (o(asera- sy) tS | = WC US629- lly | = w(Se2a)es | = S6204+5 | = 662¢5 So omly shifting u meccled which can be cicheud em Conalint bmi + Omly problema when am G large of mot porseble bo Stoxx im mounal emt. Mettching ol o Constant Luwe Sou emsidr modulo curithmelte - emplayes reccmance selakion tov | ber = Colts ~ TEs# i] - 10 Mmmedq)) + T[srome]) aod 9 | A348 407231415 2673 49 2. Qelz | Cie 2 1 fees mod 3 faodl i Pr Biya | 2y 27 phen 2 module waluu aut epual pufoum comparcny when 2 modulo wtlus au clifeunt tb thew tho Me pallan | count Match 14162 = [tolsrqis- 40° "3 mod 12)+ A) nod 2 | ? [to (C31uts- 30000 mod 13) +2] mod Iz \ = to[arqis - g]42] med 4 2 (0-3r4Ob42 = 3/4062 mod 13 =¢ dh ts pmodq) Hen tS 4p bo shye Sa rmualid but dts sphnodgy dew met Oleoays meaw tsp Check alm chenoclu Any shyt ¢ fo whioh ks = plmedg) must be teslect further So the tut ts = plmod g) helps & mule cut tmaatid shy S Rapin taup- Matcha (7, P, dg) m: T length he a™” med g peo bo=0 for F< Om ff Peaproerssing p= (dp + PLé])mod 9 fos to + TLe])modg for $ <0 &a-m Panatcheng f pez be te PLI..-m] == TEset ... S41] b Peultun ooowus txt Shift 6 8B. Sea-an tu. ter = (da (ts- Tsti hk )+ 7 Ese mei]) mod 9. 22 wu aH & SP > | When © u orecudtd t& hit - 1 checks fot gpurwas hit Prsproeuncing lie = cam) Matcha bina = O(m-m4i)™) Shing lian = bw Enpeclid Motch = O(nem)+ Tieme for spurtous het - Oy KNUTH - HORRIS: PRATT ALGH * Computing Prue Atnay Patten: ac acabacacabac ac ac Take a Cemmpouuy any tofuch ct Of same ege of pattur Eauny pocat on Gomporary coucay tril BU ws which uw the longest buff Length cohiok alo has-the somu o prafiw at Luuy powit | | sfats| | s]aloleiniaiw| elala | olelalblolelalelalgjolelale iol | |ilalalolrla)s 4\s 6 Fe) 4 1 H) uu io | omen TET] PT LT Semoument jor | | | Compaut v(Q:uy) - | tt 1 t | yo ave ! | D pul joerg 7 | fee ie I | VCO. Yer j : 7 ow (Hy Ji : ‘ VO? VO) WO Hg i e rc | Jel J Put o> Xl6) | Ved? UG)> yor fj oT fete jae | | J oT | i | | i C | cb | Tomp 3) longest Suffer which abo Mal cher pufim ws Ch ftom Chae auxt $ charoes amertch S prin | hast posulton welt be 3ero, f after deseanenting oo Onaleh prumel- KMD. Subslumg Suuth tHrus gre tut abebog le ->m Palta- begl —>m | Woast oom OCamm) bone (akin KAP pufoum subshhing soxch on Olmsn) teams: toon Text» abcxabedabx abccdabcdabey pelt : abe dab oy | Text abxabeoabe a by | 1 23 | & 6 pall: abe a by | eq fololo]r| 2 fo] Proper ous | abraheabeaby | ahe aby Puta ec So agai ¢ out farm oy patin nd a? abrabeabe aby. hoo of tet boolzo! 7 t ahr abc ah caby t ao need urruiong fo 136 | abeaby | ti hw Just mau 2 backwords | So start Cmpauinng row ¢ aby unth Coby | Rantione Conplertly OC) ams langth of text Runtime bb bucld onaaey » On So Lote Cnme > OComt n) Space lompleacty > OCm) compu. Paap Facleoat CP) am. P. Length het [t]he 4 rer Ono npiy=0 ko for a= 2 ba while k>o and Plk+] ¢ PLQ7 ts Xk] of PLen d= Pl gl] Does ker *fa]-k Rolo © | Compats anatohes P agaenst tb ef” Running Tiame analysa | Ran ning deme of prtfion fo « Blm) @ | white 6-7 execu OCam) trans albogetu - Mabe an-1 duolwn hen 4 slab) Keo. and K tnorronenttig at Lin 9 tors exreuted! ortth for trop - atonost tres per enceritiom of for loop-&-00 | | > > FRM MY nN Dow > Tolol cama tn £ = Ms eq on enlinig fos loop» €ach elnalton af loop thovoment 9 So arpignements wr Cro 3 ond rq enscas KEQI<¢ fora Qzl.. ™ | a chats Loop duoeases k 0 Kaew becomes - Jotét cesseast of K fom while mp & bourclia ftom obow by Cotes Cnoreose Of & ov Linp 2 am-?- @ KHp_Makcher CTP) BF Form UNH dS woe + ame T-Length . m+ P. Longth Ke Compal Pacfen.Fuunclem CP) qi0 -n0of characla matcheo era ~> scan tut pom byt & cughe whi gro and Plate] # Th] Q= Rg] .-> nert choroclir dloesmvé amatch Sp Plas] = = 10t] Qzqt! .-> mert Characlts matches qe ls ay Pmatotud 2 ‘paltun occurs totth shyt aq X0q] bee bm rat amalth ®) a | COMPLEKITY Classes - \- cto P: Yes/No problems auth a polynomual ham culgan Polynomecd fim onecuns | | | Ih you ou gruman anay of a Cnleger i /Oa,.- An wean asked & scorch an elerment ty that. shir can he acheined ty | tunncng & fon bevp (€ om | Searching among m nos: OC) | 4 OMG polyneenial tme | Yes/Alo problems anecins efseciacn problems | lays up: beewsuom prcblamy - Ya/Ko problems with & polynomial lie | “checkeng algonither amore precy tly gras 0 tolutton (kg: Subset of wel | Wecan cheok in polynoanial tems Y that soluliin G what eve om lockwy | fox Cts tk o Clique of size ta | clagusr- Hears att mock tnluconnsclisl & tach oltes ° nave Ba chow Peotuded age we Can check Y tho clique 0 Noe S prowrcled a solectim ese corn aucuefy polynoonial terme | aBep - a aol o clique © polynameat fn . is PENP? % 02,03... An — Soattng O(mlogn) GY polynoaniad terms 0)’, 0p’, a3’... Qn’ be Scalia oP Can we cuaefy 2 a eorlid anray or mot ? Foa thet check Y AZ A2¢ ag -- Z£Qn1 EQ PENP ‘ue Penp hut P#NP Fg: Show that CNE-SAT & % NP? p- Find a s0lulion w polynomuat fms Ne- Check 0 soleelem ur polynomial Cnn Vrotsol boi How b procws a problom & Wp Complete 2 = Bekma NP Had- A peoblum Np. hoxol tf all Other problims on NP com be momually keduced & ie ret wp kes: A problem G NP comple f of & om NP and NP Had ‘The most: abifcouclt problums on NP fh cur tolue cm NP har! om polyncenial tunie then P= NP Alp. | Complue proputy oO All pans that axe on Ne that bas he seduced & a Np. complule pom im | polyrecual Ls € NP An tur phomalh com be xudleieed (0 NIP Complete pbm wi polymoonead Gui —> fon solued Qruwur com be setaced os the onsite of NP- j Po | NP— Hane | due femal a bolultn for amy NP complete problim - aneans awe have fy | Golutuon fox NP clam of problems | Neel of Atp complet - Froudrng a polynomial trom joneth {tempi plan ps Sead emech oigouthon fox aay NP How b proous : Grusn a prblom &- pu NP phers can be tecluced bo NP compli ' Quy NP Complele pl coun he Soluued tr polynowu'cl tix Chen Ol! UP plms can be solusd vr polynoowuienl “Cus Thy P= MP 6 pore selutiom exes fox NP Comp Cole pom - dhow NP plu Cannel be sclud ry polynoanial iu | Proow cx problem & MP complete : | Reoluctiom Method To promt tx pb B as NP complete - (b hoxal | Tea that take a NP complete pom which & abeady known be be Ke-cenplel Rephiose Alog Rephaouing emapluyca oH polynomial tune - | Fnslanee —y——. Inslancr —s[Potynomal | % : | Geof A Potynemutt poof we nye Fi eee —s pele Tame Recln ta Be | © he | Bleck Bow ' Tastaner wef A & homfoumed, So mow which becomes am Yp fos ph B | Reoluuclrem wi polyrnomicd this ax polynunuial toms algmy (clan P) 1) ea | To Show bu Kte Compl. Osté wu ti Ne © Toke a pb t¢ known & he AP cemplelt , ancl Recluce Ue te phm BO» polynomial tome Cneerall phn Of Solwurg A cuing B hos 2 parts Cfo clecuion phm) olhuwae 3 pare Easy (0) + Easy (0) - Eay Eosy@ 4 Yad a2 Yao Bord acts leks botttr oeck Jp B com be solued om poly normal Cue cé (P) «Then ts P ushich Contact | ch orsunpliow of Aa AIP Corup loli + Bence prooutd | You gprs phos - Comet to cectien Pls. | w Quaph coloteng ph - Amd the cmiincanun no of Celocus Dieu im - Con & graph Colowud tengo Colou Css P: Poms that aur goluatte tr polymer tere Pbims that can he solucd tn O(n*) deme for soone unstant & and Ns Size of put b phim. LloasNP + Phams-that au werifcatte ch polynomial bans Peuyfeale: gireen O cerifecate of @ soleeteery, toe cam eieelfy ewhethes he eurelefetals Us corecl in polyneaneiel “tem Fg: aurupyirg O gruen clique 3. cme Goutts feability Any phan PO AID Ih Pabmu 0° P, then aue cam solwe th en polynconiod time without enen beng seppluiol ty a con tepeents POND Ne Coomplele: day phm o Eu NP ancl NP harol any AP complete phm oon be Soluabl or polynonrad Gare then euirg Atp phan hos a polynoonrtsd mts olgm Commonly useed tp Complele phm w cuscutt cates frcrbelety. we Foe thal qualiees Of Yp, the ceoeull well qeue Op 1 Pacers Cleque ph w Kee Comply Show Cheque a NP 6 3-CNF can he seduced te Cque Beer u 4 Clique grun a clique wimg adjacency amatux of each wouter een proowe conneckeclnen of aertix So NP. 3-cnrF phm U olwacly brown as NP Complele SNF Recluclem! ko Opa Polynomral om aly, 2 GAGA C3 - Cn 3cnr ‘ coteuat sat ” gach cloww conten Ovevb. Ch VOvla(h via) A Neca fe Lransoum this fe eulance k-ehequ Potynomcad Sane sigon dns. ~ Cor ap of Buse, tre aetenal Case Hans Ranainng teane algouithan & Ofm*) for some constant h. Atl problems cannot be So(we tA polytoméal brme: Taring Haultig Problem: connct be sotued by any Compeitur Thou aux problems which cannot & folurdl tr Ota!) tums Sroblems that ae scluable by polynomucel bony algan cated ay Traclotl: Pacblerms that eget baporpolynoomc terme Us nbactable (had. No polynoamut fume aulgmm hax Atscound fe ain NP Comphele problem “class P- consisb of problems that am soluabts tn polynernectel tems Paw blems thett coun he solued tr teams O(n) fox scone Constant &, = Size of Yp problem. . : i - Class ue conesh of problerns that qu turifiatls orpolynonmct tis i Grauen a eerig cate’, tolucligar“eue Lan woufy the eestfeeate W Conseel 0 tims polynomial @\eseef tp of preblom | Ege Ginn a patb, can cheek 4 the path & Harméltoawan eyo robin SCN galisfcebclaty , coutyitale wtowld be wrignement of eelees b sariable - We can check o> polyncemtod line that assiymanent Sats et boolean foumula any pachlem wn’ P & also NP. as any pblim Pu solucbte 4 chacously aunufrable ewclhout een sepplued ty a cntificale So PE NP Ne comple- kU 05 NP and & as hawt as any problim w NP Hany np complete problem Lan be soled i polynoanceu Lemie, excerss btoblum tn NP has polynocmical tune alge + Host secatst beleewe NP Complete problems as mbactable~ Thu awe 3 hey concepts vi showing ¢ a -pacllere. fo be NP Comptila Dreucoo peetlomn vs Cplomizatton problem Epleangatcon problem wy whch each foasible olution has cn ance ales ucilue and cut weeh b frord @ foastble sclutom wth heat Ueleee. + Deeeecon prchlems au those i» which nsiin ch ALamply ya or m0 Relatcom blo eplumegation phan and a telolid aleeu con problem works w fawoce then wwe want to shew te ophmtselom 4 hod thea if Wwe con prouccle emvictencr that olecduin phm & hard, we abo cap piowa eurdliner that rolalel eptionizatcon problem & hava |) Redtercleoous The motto of Shoutng one problem | anothn apple when oth._proble Ou gees wet problems. Thy clea a stake b prooue {AIP Comp irs. bots t clu a dacuton problin A, ea Shpul & particelas phrn u Called as enstance of that Poms epee be knoe how & Soteu o cifewn daexécon phe B th polynoomtiel Gore Fry we! hous a procecttue hat brounsfoums any wislaner 0 ef A enlo gum eit pot @ wtth the ‘ fottouning chauactuistees : \ \ oO no barca thar ss Aescat ue the samt, we onset of 6 ans of PU Yes Sucka nocedu called as Polynomial he ° r “d fet kin OE” Tbe iste wal gaa — | Chaos Potyearnaal toms isa _ Sy ee 5 Nara | a ___ Potynormucad Terns agro & cecal 4 | Reducing ™ 3K £4" Poltoud. RhoC!4) f : : . we 8 By) fer 4 Nek » 3 yr2 t lee ue dohule Thue / ir2, (2 | rey _ ay = 1 ano 14 32 Get med 14 Fy 2 byrl tod ITD d= geo(a-3, iq) =f | dr Gen(3-@,18) =F br Geo(3- 0,1 | peo ay yolesk Qere | ih ceek Bz-y | yo? rou ty foo. Ut Kiergt 2 - fos). Xi > toy med) Mea Fx) mod we DK? et eo (Fd ky ~ v2 |) me) Hopute:V ! | Pobabulslic Atgouthon ~ Some culgonctham behaue cefferent avhen ub u opplud teuries for te some tastanet. “26 execuleon Amu and eLuen ofp may vary emmsictorably * 6 allouud © go t cnfienele loop dition by joo ot peouudded of cocwus | with reasonably small puchability on any youn trstance, | alge geo Stuck, scomply testart on same uislance fon a push chance of scour 4 ip thus y amoee than ov Corel ances, seuual olffacnt nay be oblaunsd | by cunning probabilistic algorithan anu than once =| Algom whow the wueell and way of xesult eblacned olepend! an chance | Also costed 0s Randomised Algorithm — dlepencls on tandorm aes for tbs Oprrateoas | Computer comn genaati on Preudowandom not. @ Nos that axe genualed by | apie bat meennbu Cooks candom. | _ Honte Caste dlgm - Hoy prodlivcs ineorseot wrull with probable? — bounded ea pe shabhly Randoanized Algms \ has Vegas Algre — produess comecl cescitt ane only uration from one @ anothu un ke the hunny tem © Hoolyfeid determina tic alg wstutch uses eancamnoy om decision + When dead ond xetal the algoutton | Monte Caro ALGORITHMS. | Imconporate puobabulely into ana 7 sed evhen ave brow that a set of scenarios can happom but av rintus of tohether they will happen | oman world as a syslomn + Founelate avoild os battle 6 + Each sep ot dexation pi 4 tual Sf world 1 'yslom tll euentually eontucrge to adoirab meas we t HC Qoed for: Examine complen Aggregateans fon stomps o.eleows \ nconporating ceneerlatnly onto analyses | Kaploueng anintecbon tect | Semplfecateom of comptor systame + Sconseemaly anaes onestober + Peobabulity w Eypcal fos Monte Carlo alms that gobi clectscon phim + Momte Couto Colors con be geen an euplecit Upperbound on loleat. enon | Pecbability | Appleone, (0 Gptemizatiom stun 5 panty coma foma probably de bebuteon Y [Dm ancetocleotiones Engg. tb analipe conclatid ond uiluconclaltd uaation | 0 dnalog and degelal integrated cbt 12) qeoslodi Lees ~ arnenerel piveasiong , flow Shere quantitate Ae cnatyse. 9) computational bology- Stuctyong brologccal ystems (A Jating puonalty of mor (DP Decteleng Set Equ 6) Applicateoms Cryptography (9) uuyying Habicx Mellplecalon r A keinclomized alge ath delumeaus ke running Gam , but ofp may be fneovset wth 0 culain piobability Veufying Mater Meultyphrcalton Consider 38 nxn omalrias A,8,c ket C= AB Meultiply Aand & and compare woul wrth ¢ Ip eauong shiaigh(fourmd mali amultplicaleom algonthon tho: tabs pun lms Of Olm) + Stranens Algm 6 fos and eusn {asl lor onus fo aery douge n tut the asymptotically faslisl algm cwnentty known alll kequuu a meen Ofm?34)- f wie au eotleng lo foluale ct smett probability ef oe ” Cent om OCn2) 1s suypectent to Sole This preflear a Cohen tue peobabiliste clgm O(n) a Suuppectent ASsumu C #AB rr ¢ fu onal: ¢ now of d contains allecal one non joo deg Console. cony subset Se $1, 2,... 03 / — kat 2,0) = vetlot of tengih ba obtained ty adding porit-wtse the KoWs of D indluxed ty ofeanents of & For tastance Ft 3.43 (2) 6 oblarined by addhing fost 3nd o tows of b Testirig whetha ov mol CAB by computing =5C0) for o tandemly chosen | Seb S and Comparing xslt cuth 0. Thu can be dom ofectiauly by wrtthout fast Coomputing b : | Consider > a 0 emabuin melleplecolton of «6 oun | ers ahmary actor of kngth a 2 AI if Jes cand %-0 othaurse | . . _ We j We enn unify sharghtty =5(0)= x0 @ a ran nalux | So cox tut & about checking whelhu x(ne-c 4 0 Ol AB = XC for wancloanly Chosen bunacy cuectos *. Habu fare of OCn2) compute XAB - Os helio t Compalt 4 bn matlitx X ann. Inatux. Funcltom Fiurualds (ABC, fon (<— Hom do %<— Undom(o... 1) - Ih (#A)B = xO then xeleun True else Reliun FASC False 05 Qnsauer amecuns AB AC, eegaudlus how onary Bimeus ous getlely i Ams TRUE 9 Comselo a 3x3 mate | az [) 2 3 p-/24 4 c- |" 24 37 | jas 6 ts 4 my os | 764 265 a 4S | | | = ya | x= [1t,0)- benny eectox Ly Aca om Funiuatdt (8,613) outs x2 [2] | xas [1 op ft 9 3 (44 ers 346] 4s 6|- yea) B14) | cae: (B74) [3 ) ; 2 fisnite — saas4sy — dorearys] | s 4 | ; ‘| [40 aq re] xe + C1 off 24 27)» [i129 vanes 37441] 29 6s 47 a 98 2 fo 9 128] > cal frornalls uth x= [or xae for gfe 3) = [ar see 644) GS 6 y é » (vu a J 2 (nse (O18 05) 1g) + (eaptze lt eset 4g enF795) 1s 4 2 (t loy 336) | es efor J(u 2 34 )> (1 thy 136) | ag UL page os (x Ae 43 4 4% Go aut hous b Aapeort Facinalds b tinwes Function Repeat Feevuatas (n.B, ¢, 1, &) fote-1@k do Nh Fremalds( A,B,C, m) = FALSE then Reliun FALSE Retun TRUE, Sh au the K tem, olpo tue then C* 9B I) C#AB, Jon cach cat on Frervalds that d wit action tun with a probably o to. Cincoaect) Probability that & successctue colts each eeloun relunn vovong ansiuts 4 atanest gt | So ween concluice com alg & 2" couset | When keto, he & belle thon 99-9% coneck- ‘Pecherbility 6 typical for Monte carlo Aly that solve olecctem paohl. de th ansuu Y obtained & guacantied & & consct | Mont canto atgms can be gineen an oxplrect eipperbound on lolviats evo prcbobelty Feunctuom Freeeuldleepstlom (Au B Cy, E) kK—[y Ye] Rel Rope Paucualals (Cn) An odateenttige of-this aerseen of aalgon a that ue can ancelyse tht runncng fans a3 0 functivm scaneltancously of urslance 8130 dined exor probebildy Thorlake Wins O(log Ye) Mint. Ct (WA NETWORK: Hem-cut means oruoucmum that fh | hae req sheowna pein & ediges Should be cut from raph, 8 Randomized Hin-ceot Alora perfoums only wher then enut atleast 2 uerliers ancl ore eddge. Rerrdlennizeattom & perfoomuceel for Selucling eclge Tind_Mincut ( uaclieetid Geaph 9 ' while thee at mo: of modes > 2 do 2 Pio an edge G,w al random” Gg (3 Combact the elge (4 Rumoue al Loops Ss Oulpul the temareeng edges Fa |} —-—-—-8 MoncutG_ — bohuele Ivi>2 : | { Sotoctand vdge Cry) € Q—> (—— tnsfounty at ca.don | contact Cy) | Retuun Let | 5 | Comacela the edlges Ge), (48), Go) Combat the oage an Remow al i 6) | (cn) & > ne | ®) Pee | ff | Ld) (th d= ncen cut ead peettetitcle | Then G has alleast ho ealges chor m+ mo, of noclu wh gaph Simes graph has ancncuk of attest dl, it must haus amincimevm dcegeer d, and thu alcast dn edges 2 Puchability of pickrng an edge belonging & cut en just Slop ote 2 [LIS vegas ALgoeinucy |= nenctomnegee algan that alucays gran Cousot ascot ov (L trfouns abt the frelon + Ege @eurck Sout - Pintot chosen raxctona, but toselt aloowys sorted t t always ema Ofecluely, but tk aay ofp 4 symbol not past of _ Golulisn space tr wideeab facts T Nodytid cletuomenestic atom by wing tondomnex oh clectt cen 1 When dleac. end restart the algm + Mewiage reennving me anetlysct eumumes sores dlirbrbatton ef problem inslaneu £g: Qucek Sot , Sefeetom Sot | £g= Cemscclu: problum of feodteng a’ en an amay 0f 2 elements , | Taput: An cw.ay of nd temnens » which hal au a's ancl othe hal bs | Cutpett « Find an ‘a’ in ase | Fienetenga. tv ( aay A, 1) Begn Repeat Randomly select me element: fron nn Chumentt | Unt a @ focend | Fool Ngo succeeds with prohabelety 1. » | Quek gout + Afamcliar algm wheu Keundeannen 4 dmployed = Detrumemeter @turck soul ECQULULs O(n2) & soit NNO | ~ falgmn selecl prrot element at xaotdom, Olnlog n) Hane Keqiued + daplace -| ty eequus O(ntegnd Wows O(n?) + Diawde amay into 6 and Solus eecouusiruly 5 coud ns ee pict therment canclonly Mea ee 2 @ 1 9 4 nar weluchd 8 atl wwalle “Cument @ lt of pro! faxga elerments & taught of praeot | | Pracol Seloolid xandoon [ omen tach elermens Uh pruol ander i ond = Exch, both @ UG Cument ebemmunt < Pieol Exchange cunntnt Cerment Certs ob 2 eo1% 4 ? ? Tyre | a Vv 2row ¢ & @ 4 7 | 4 . i tinea ome ofan Cussent > plot | e@ 6 9H > i - | a + tot Simply Susop me index <> prwt Selsclzom Sort: | of 1 tm vat er | Ye yo | Tet 1 small Camus S | s2y 9 4 GCF yw , 462 mo omievel:2, — CrCheg 1 pote with 2 , 8 @€ 8 4 97 PROBA BIISTIC. ALCOR ITHNS. Randomness useal in alguns fo apptoarmate Soliton of mumuicad problems 4 Close oxarmple for aucimnerical prohabileche atgmn sconulalicn. Eslamal amsan Length ef @ queue w 0 sqstam so complar that uw enfeasublr to gee Closed fous Sotcattoms ox mumoical anseuer by citucminit lic amethed Anccuws abld by Probabilistic alan a approwmaticn, but ik expects precitton Compo actin. jauatlab to algm encuaws. eur ¢ _ Jannl 6f wso%k performed 8 lo obly tre odecteomal digit of prctiten, (00 limes auoUk ex ecelic Sotegua Pree? wa conttinuons function and q a <6, than aa of the sonforr bourcs by the comme y= fo, Tho t-ami and the wotreal tones %=Q anol ¥=6 & 6 a fforde a —}__ t 1 a b Comsida a wotangle 6} wxdth b-a and height 1/6-a. as Shown. hea of uctongle and sunjpet beloco cuuau also of game Aiea Ano! Sams wtdth , Chey anuat haus Somes aunrage heught- We conclude rat cueing heightey curus bho als @ 2 (b-a)- f we labs a pernt beloeo., (0 take cugatow hughe, ther caluprete. also Aotolt fou anbultuy continous fastion f:R—>R A peobabilishis algrn jor her &- To esteonal amg haght of conus by xanclom samplay and anectliply result by b-a. | Saretion HcimeC 5m, 6) | sam <—O | fou (<1oan do 1 <— unugpum (rb) | Stum <— seems fOr) | totun (b-0) x (Seum/n) | | Analyse Shous-Chat uatance of estate caleutatid by alga 3 ciaeusly | preeportiwmal fo mo. ef sample prints. Dahchalim of estrmale & approximalely | moumat aohen mcs lauge & alimal: of ence ot | d Viebia | A tcasom bo «we HonteCeslomnteqatiom & when tut haus te ewateeale a omatlepe entegeot (dpa deturminusle align & sannpls the flr gencialized fe seucral dtoncnsiar , the no | Sample points nected f& gel deter precuien gous exponent rally -oxch chimenven of miagral b& be tualuated f tco ps merce b euatuale a sianplr nleg tall, then ‘© aie (0000 pb ef a oor 100 gud f> acheeut Jame puciiter when double tntigeal eccaletalid » Ome mutton ps cstlt be neccted foe a buple calegtod . fn NCaly,, demension of enlagqral hos little effect on prcesscem cbtd, eucn though ant of work fpr each Uralion increas slughtty wrth dimension Numi « ced fe entalate enlignal 4 demseston fou 4 heghe % mo chee Somply Uchniquee can Compete Beller algmms cub bul with anon Complication Precerton of pbms Can be Compe ceed sung hy buecl Lichnrigues pautly Systemmatia and pully probabtlestie Counting doth an m dit regal, toxin oxcinay. ot Ser can count upto ati fom o ‘The ugulu oan count mo anon than &” duilincl Ualues a UU the anak No, ways fo set or brneny Ualues we can count beyond 2” & ws Skip (ntuos dar tales . kg” 1} wwe count only exin nos ttt Con Count Upo lies cbabatl Waluus Kee c= mn bit tageslu Baretumes Cali lenote the integer topeesental bray fy the rages (Sino proctdias ws complemented tratCo ; ckCD @ Juncker Count Cc) | counter) = Retwins. the m0. of Calls b toh) Sion Last call en cnet cnt Cc) - Resets he cocinlr & 3e00 lekCQ - edolt one @ county count) - aste fo h consent walue digms Should be able & onainlarn arbitany lange mo.of eruntest C1 C2 --- No infgnn con be paused blur Calls: exciple dough tugulr w@ expliout pacameler. Wf detaninistic counleng stsaligy eoventing connok stip walues. Thaw & mo atu way tcck con add ¢ fp corenty for any oltoe call» Bohowior of UckEawn anust be | dlotaeamencel by cumsant af cuatue of ct thu @ value 0 9 URACO temas unchanged counts willick ab that pe until mut co) Called « A detuominuslic counting ‘nou than a” ouonls to an obit agit © tmporslbt- Fle cut hows € lax the rubs teluun the be: of Ficks Sines last init i A profabilétie stintgy €© count tuubt fas &- Regula ano bunawy count, chutiated do 300 on ang cit. ete iad sated pace, {f headl- ado Ib kagcalte + f taut lo nothing cohen count tt dalled releun tunes the | terlue alsned gate © peowealune tnitco c<0 PHocadune beokcc) foo cic do ih coun = head thon xefean cecer I Pkobobility of overflow «3 too Small to be woith checking Function counrtCc) Reto 9S | Counteig turce fox oneons aplo aln., which can be achuued actually bY O Single | addubmal bi 0 Kegciters Probabuldle counting Saabigy com count exponantrelly | fata 0 © OLY « 8 hub au sufistint & Count onow than Sx107euumnb. | Fos tut exp register an ostumale of legauithon of actual no of ticks. count telmn aoe Senor count ef 0 & be ssprasenled Wwe Slat thy slab wacky ¢ | Cus ediaral of to.of tok: breomu 1-1 ceuth probabelity whl | wwmains 9&1 axt complimentary probabilety | P | apeold alee Keluined by count Co) ofl tha lich 0 | (ath npsetntep = 242-1 | | | | | By matéimaticol induclion we can proous that uaxtonce of count afm ticks fa anln-n/2 - Slardad ceutation w toughly toh of actial ne of cuunts | kasegas Algoruthans Hobs probabalitia choien fo hulp quucl thurm mone quuchly oo easiest They news tulun a uneng Answer. 2 main covleg Ou ef las wages colg ms onal 1 ce tandocmnes fo quit thet stauch § 0 cobuet solution 4 Guusonterd elisn | anfostunate chovees ae ameicle © Allow themvelues te lake usreng Guns that | bung thom te dead ond, u statu ih mpoucils to ford 0 solulion wn this tung cli hasaregas algm of ype used when a enon deburminsstie alga by colus a phen | tens much foste om than tn worse cose fAUIcksoul - Inconporaiting a element of Rardommer auow Walgm & umn AY} ble gerd and bod untaness | Funclum seleclwoty (1[1..n],s) [ $ Feds the ¢gancillsl elimant rT Ie Sone | fet jen | Repeat i £ Arse bus» T01..j7? PetL unifour CO) i pructbi CTE 4, pk, Sek then jek elie f $2 | Mente b ele Retin p Procootaus Quucksorthy (TL...) {sorb subouny TL. .j) entornen deeuaseng xd? Y jee a supfreunlty Smay then tnsal (1@i--{D else Pe-T Cisrsfoum Cpl Pewetbes C TC, prh) quachsont Lv OTe. £)) Atuchsont kv (70657). G nploxcty Clee of Loundomuzed | Alo RP class Class of cecisiem problems for which the a an ofccuent polynomial Gms Kanclomiged olga tohich Aecogaczer NO trslance with absolult | Certainly and yes urlance with probability of atleast Yo. | Zee. Problom classes harumg algans wrth polynomeay farms Cuerags Lore [running fume whase Op u aloays corel Chas vegas) | BPP. Class of problems fos whroh both Ves and Ato (rslancu ay allowtel > be edentyfced weth somu euon ° Represents the cham of effcount | candomaca allgns ZPPC RP & BPP | PP. Descutbes cleciscon problenms asth a polynoameal tamu digouthm eur & mou acourale thon probabuldy Y2 but enor prcberbulity cannot be bounded auoay prom Random ed Polynoancal Clay Reclass) - & the complexely class of problem for whech thon ens 3 propertte 9 SE always tun polynomial brane gp size 2D 4] Comet ansewu & No, ut always teGuns No. 3) Hf comet ans & Yes , Ut seluuot yes wath proforbululy allecst Ip DION'S FACTORIZATION & a genvial peepose integer [ccleugetlcom ancthod , bastel bn finding tong usuet J sgaus modelo unlega Congreuenes Gf Sqacus : dng contegar om canbe eeprecentid a n= vy? = (04 pap 224? = omodn & n[a?-y? Garyperg) = omodn DE sorme Hone nr nevtha denucles Gey) o% Cx-Y) alone £9: n=3s 36 mod as =I 86 = ¢amod 35 Facto =< Geo(m-y, 35 , Geo(X4Y, 3S) Qcep (6-1 135), Go(6rtl 35) Us _ Dekoats, Theosemn, het on be a Compost entegus « ket and b be a oltsteick inlegus blo 120-1 Such that a+b zn f a2anod m = bancdn then gco(arh,n) wa aon- biwel dbraison of Comidu N= 2534 Aut A= 2012 and b= 29 ath An 2012 40127 VEY F QS37 aancd n = 2012°amod 2637 9: 1sas Re (69g Banod” = acl $22 Soon +1629 q= Soo R= (b29 i a? = (545m +629 Q2. bs mod ti a®ancdm = b?anodn ital 7 Hon a#b and ath zo. Theosem says Geo (a+b n) = Qco( 3/39, 28394 43 & anon Keoual Arter of n & Select any emligu rk 9 Choose an lege % tandomly from Items 3 Compute Y= aanod 4 Foctuze Y Sf facteu ef Y au pace and oot an elment of & 16 ghen choo anothu tnlegn % else Cooutwuck ker x & matux Mu which erty Mij u Zuo th J prcane appeass be be an ener pocuar tn Me faces ef Ye 7 S — Othauue Ae 2 Fg? massa .k=F Comsictuthe 7 paces 2,3,5,1, 0, 13,17 Fast tonlegus blo 1 and 2536 Say = 1769 Cleutak ds squcur medulo m: a%= 123304 Ryo 116? nod 2537 9: 1233 &= 1ay0 y = yo Faclouge y uw tayo + 24xSx31 He | Farle snes 37 a oot decwiahe by any of he adomaside ZR Pe Pacomes and abo 31 & mot in 78mooth os 2 A 2 31 | Second attermpt- > 2y55. | dul on? Galeulob. Sete amodulom. mod om 2yss2mod 2539 » a G> 2375 2 l6So 2, Focloune y > loso- axaxs Kt 650 | “am | Record, comtorenig (hes lentil @ buccuE 2 Tes: ' = QYSS + 16S axaxs xu “y \, = 970 Ya = 200 DKS KIBKUF ae %= 0S yg = 728 Q2PKIXIS a ; | My INS yy = 2296 Bex 5x17 As 2 2b Ys: MO 2x32vsxU | te: 8 Ye. 32g © DXB KIBKH | Ag = (UY yas you 22x 99 ¥F %w = 433 Y= Dogg 2YKI Ie tr He 2 3 5 F NB oF ka ‘toto o0 ' @ © chkow corsexpomds b one sucrty | he o@ 1 9 o ' 3 Each column costspunel t O18 of | Lo © 4 0b © | Aclamessebte preianes rfo t 1 0 @ : sft ot © 1 oe t]t wo e@ott | r}Jo totore | sLo oo ol 10 Tirtows bhould be Selecled and amu | utiplicd based on folloun conditoms ° | D Eaponents th the procuck ort euon ue ¥ wd 2) Thos aust exul a nom ermply sel- of tems that adds up ard fr! the ktmaindn using qodulo-2 and Kull Choeld be 300. W¥rYyyg = ake atestx nex 132x177 Ys Yy Ys Ye ¥a > 08 x a! x etx 12x NRX IS? % 7% | @, Expomenb th thee au eusn- Tun find the squeue joot Of produc 6 folreted Hocus , then wrth aod a and tu tuomed as a ‘as [RRB TRE TRUTH IBEX 172 mod 2537 = Dana Ax SP? KUK BR 17 Mod 2537 b calculated as b= Ny K Hy XM HE ood 2537 = 2YSS RK VIOX GSE XY 33 nod 2537 The condliteoms a2 anodln » b2 aned and Qtb#% w& gatifed @ and bam tnleges bua land m1 Gul when que Cos Yr 3 Yo Ys Yo Ya s a= o8x3@Ks*x 72x IK IEXIF Mod 2527 = 1972 be QUES X NOS Xiyse y2/b¥ COX (EGYY Mod 2537. ~ Sey The quolaby te condition arb sn Mopuse SOUAE VI Peltemene cwhethie any pes | lone segrmenty ntact WEEP TECHNIRUE fot of Sweep hime Stata US PEVENT Por Reine seucip lechnque & cn algonttham fer deltmemong echethe any treo line | Begonenls ma set of segancnls unlescet thes aulgontihem ccs technique | Calica as suueepen | Atgonttham Kerns tn O(n a tame who m= no. Segements Cue ake Gruen St Acteeonvaes coly whethor ox not any trluscelsain euuts, Uk dowsanct print at | tnluseeteons [Inoout cox b fd att entusrbi asl of mtensegments cont nb | dat Seucrping an Conaginary wcrtioal surcep leat posses through goaun set of | gevanuhive. ebyjcols feoan tft lenght. Ihe spatial dmeenseein cofuch Ue suceiplin pmrcaues crorons,, of terben as diemension Of tume, hoe % dimension | Yao anumphors ou made : GY No tnpult segment w& aeorbueal O/No 8 input segements enltasict ata singh pont > Didkusng Sigmment [100 assume cro extioal segment, Any gp segrnint enlawecting te scverp Cras wt be cot ore pothe. So we can oudu the seganente nlusecterg bu auserp line Guuth spect & ther y- woudhate of punt of iteueelesn | Tuo soymans $1 and $2 axe sad lo be compauable at, 4 the eerbial susep Gena with 1 coorclnate % cntuseets both of thum. KS; @ abouts. atx, We wpnite as SXyS2 » Hans Sand % axe comparable at %, Inluscelion of sweep lent % with 9 O hughes thee eatuseclton of So _b (® Aaduseg of lene segamends: Obs.c; ASLb, HSLC, ArtC cin SUC Segment A 4 Mol Compacahy toith any other segonenb h Seganents cand f , they Aree otdus aye. infusecling Edy. but fAwe ar scwceep Lie an the shaded aagecn hos sganente Ceand f) tonseculiue n Ceclourng grown by ex Tor ang grown %, the ruler dau ketal precoder for the segancn ts tritervsecting te seuciplenen:. The dclaleem 6 tonite (81> 9S 2 SedHS and nefloninse Segonent on(ta oudawong when us left end ponl encocnlond by swueep and it Wouees oraleieng when tight enofpornt w entountud Mowing the seumep leone Suuerp laine algcrthan manage 2 set Of datas D Suucip frou ‘Slatia and 2) Equent porit Schedule 1) Stucep ine statis grows the Kelateorshyp among the ebpeols that the pe vit "? ad “ 8) Euunt pout schedul uo sequence ef point calticl event pons, which ue ovoles from Uf tb mught aceoucling fo % coucdchats « ls the sucep Peogers from eft bo right, ochen Ure Bouerplime tucicher o cooudinat an ewent point . the stueyp halls, process the euuent pocnt,, ancl ‘then kéicimes: Change > avteep Lt stectus Cees cl cunt pools Thu algorithm detucrumes ecueat pourts befor % depu on Som pecpeuss of aputdata » Kach ‘the at ccipant & an et po we orl the 9 and poinls by trowasing acvedrautte ano proceed form Lyfe te eaght. When 2 0% ances endpocnls aur counlicas and Df thay haw sarms a-cooudtinalr, tee 6 breken by pulling al kyl end pounls befou corselécal wght enc pout | 3) Wen on a seb of corwelical Aft end pours » those with low y-condenae aur pact (ust when a seqanenk left end pone encountued , ux miert Begarunt into ccueep Line Status. thon aught end point encountud, we delete segeut from burcep Lime storus. uchen Hux Segments become consecutive ‘ti (otas preocau, check whethu they inteucet Seep Lane Status & a otal precedes, wseeheek eehethen they wrtaoeet and Acquis follouring operateoas : INSCRT(T,8) ° tnsert Gcgaacnt § into T DELETECT,S) * Delele segment ¢ fremT 7 Apove (1,5): Reteun the seqanent ammedralily above segment sot BeLowlTs) + Reluun the Seqaent emanedralely beloce sega t 8 ff enput contac segment , ecech epaation @ performed tn OCG ny sing Red ion Tee Segment dnleaseclion Prerclocude Tnput: Sot S of m Lene seqanontt pau of sequins an Sintuseols else FALSE | Oudlput Reltans TRUE yf om. me mu ‘ prea Rel Black fee macnlans drug. Segment Inbaseel(s) ® Fakatgedo ¢ © Sone the ond pounls of segment th S fom left boreght, break Lit by putting Left endl point Befour aught and pork, Bacak forth ted by pectleng pourk wrth éocu y coowltnate. i ® [oe each pont pe Souled Lut ef endl pownb ® h pe yt md pout ef @ Segmnt $ © INceRr (1S) ® U QBourC7 s) extib and wnlincots ¢) oe (arlow(,9 exib dna tnloucct Dkelun TRUE If pad faghe endl pocnt of a ts Y both Above (7s) and Be cow CTs) eoust and AboveCns) niu cok Betow Ces OReuin TRUE ee Dw pecene (15) @ Reruen ERGE Analyses 1. Srotralize Toted Puced be ennply 9. Doluomeene the cunt pourit Schedule by souteng om eeqanent points cha & done by soxting arelpucnts on (M4 er 9) + uy > Coouctonatis 2-0 fou bxpt end point» e-1 Jor tughit ond point Each cualicn ch fen (cop 3-1 proces One cunt pont: [h pus lyl endl poure of segment ¢, leat S adds 8 to produ. Kens 6-7 Releuns TRUE if S eenltuscole exther of seqomunt - Boundary condition ovcu if p lus omanothiu segment ¢'- bx plrer Sand 9 into 7. pw aight ond pont ofS, me aelebe poem poorly Lin 9-10 Relwn Tue | thew w an entus ection ble seganents soraounding 8 ch tolel puocely - If reganents donot mntusect barn Cletus seganent ¢ form preouclo «Featlly y awe cree fren any inteuseettoa af proosssing cal! Qn euun pound - le gelusns FALSE FQ: Eaeeulcocn a a c b wese eon eoee > Tio Foch qualicol kine & 6 lore at any euent pout kecespt for tughtanost susewp tae , Orekuceng ef Seganent below each saxs (ire = Total PuroudelT at end af for loop ctxses pordling euunl pont Rughtomeal 6ceesp (ort ooceess peocentay the tighond pocnt of Segment cw Segarents dand b somourd ¢ and (nluscols each otha. Ramet Teme n(D=S Asrimn t Ofnign)lwe | 0-0 - og me (aap so “Jotat 2n ps - Qn hte ‘60 for lecp atonotl one paw euent pe | tach dual. ©llge>F Lach cng ot). go Deed OC Gr) Cousotons of day Segment dntescel (51) We welt pre A61(s) cel Actusn tru Y anel only f Mere ts an coleseclirn anniny Seganonts @ S~ Cxomiso ~ AS) wut relur bute if Vine is O Wnlcectira Weactd leghoos-thar conucrse loo - Sf the & an enterseclion Ast Will Cute ~ Soppou thou a atleast | calercolion ~ ket po the Uyftomest enlou column pt, cheoen by Keabeng Lu . pt wilh focus! Y conolinale a,b be the seganents enlirsecting at p * Senet cro entuseoleens secu to Lift of p, ovolur qeusn by 70 ena.sel fps pit lo off p ~ Skner no 3 Lines inlusrcles at cams pl, a and & become conscouln tn (las puoide al dome seep lene ~ & 3a lo oft of p 1 gow Chiough p ~ Soma q be 0 Seqrnunt end pont on p 2 'b pa on Pusey Lent 5 hn 9-p , | pumol on sueplics g tron g u Left of p Fulha case of 14 cousek befor enconnla g, Kethe, eucal g us peocencol As; on & mot prneved -$4 puownal, by 481 only 2 posschle acltars may Oca O thn a bib u cunled mo T, elha segment YU Abow o below bo letar presi (4-2) © Segment aond 6 abeady ww 1. and Segnm beturin Uherm celetea, and nabs Q aud 6 oumscoulus (0-11) Echo cox tnlasden p delecla! amd Wt Kelun tus 44 auent pe 4 Mob proowmcel by AST, procedune may hase relunccl befa, perewsing alt cunt pont ho wo & aeacly found an (niiuclen - S | LINE SEGNENT INTERSECTION PROBLEM | Do the graun dime -seqrens intusect | EQ gf te dines GPa), Bepy do entustel a not ch | if they cu paxalel, they dont “eset ;- A . Guan of gcrms Lines ane nit parcial then aro event inlscel fo " if cue noes the deecetiom of & wort Gre) and ve Py wit (B,Pr) % | a the ang Bu making 4 te aneanieng of ctsackton > ceuntectorine GRE Fh Ci) ergbeng Counlucloobunne (2) avd i othu an clockante - Then hanes lo inlissect- On oppose Scola. Chack for clucctuon asl Pe jor @s,Py) Cheek for duration of QP) wxl fo Ps ancl Py fh att ceeuning clockwse and antectockurue ’ ; Thun both indir ects ) courbelerty Aan Sb ne BAD 0 m)- opposite side. Be Mlockwue fn r eloebanise elec wie toe Py (Bo, Py) Dy . Sou side a % lunes wont enlisect t | Fox lanes to be wnbewccteng (P,f2) Should be epposrls cluecttoms wore B.A) © and .u) should be spposite dueclons woeth respect bo (hPa) DB ameght be mths rw (sR) ~ tot emtaseot \ h —h My ; Pe . RCH P,P) “Tr gens th Countuclockaue o% Clock unte Retwur CP: - pe )x (B-PO) on_seg CF, Pj, Pe) Crier Couey 2) 2 oy & Mae Ce» 5) AND ( HIN YE 143) & Yee S nan (Yer Yj Return TRUE. ese Retin FALSE Seqament dn tnsect (Ay Pe, Ps Pay) ch = diel Ps, Py, Pi) 2 = DIR Ps, PysPe) dg = pir ( Pr Po. Pa) dy = PIRC Pit Po, Pu) 4 G20 92 d20)) ano ((ds>0 99 du 40) Il (da<0 99 dys o)) kelun TRUE else ) (de == 0) AND ON-SEGC Pa Pus P) * Reteun TRUE else (d= =0) @ND OAL seg (Ps Py, P) Reltun TREE tlse | (3220) ANP On Sq (PrsB ih) Relun TRaE bise G (aly +0) AND OW. seGC PuB/ Rp Rebun TRUE: else Reteun False, Erncwuple dh = Divaokiun of (,Pu) woot P= clockwae og = Diwelen of (Ps, Pu) wal Po = Countrclockurte 3 = biavclen of (FP) Wt B = Count elockuut dy = Desole of GhiPr) wht Py = clocbwtie >o means Clockuate True - keine cnlicot co means datttlockarse $ Rue d= when pt on Ps, Py) Thon a-cooidtnate of A ult be bud Ps anct Py Y cooudinalt of Pb will be bf Pa ond by | Then 43Lx2%y and 43 YE My. | | BOF PRP... Red Lik og MOpUse: vt Connie Hel: Comex heull Of set & of pounts @ the &maltat Comusx polygon P fo Which each point of & a either om boundary 6 P ox lnaite tt. » q Pua py Re Ps Pr Pr Py he J The amaltut polygon P choos a “oy ste Iu ta Subset 6f punts of 8 as th boundouy \ se +n, Ps F PoP, , Poy Ps, Py andl alt othe poink » batt traci the boundary- | GanuAn Sonal AcgoReue Graham Scan (0). " KE Po be the point vi & unith oninimuum Y eoordioale om the leftomest buch POU wi Case of tee 2 Lob $y PoP... Pam b¢ the semmainer pownk ®, sate by polar angle th countuclock wue orola fo (4 mou than mapoent how Sainms Angle , xermoaue aU except the fauthast pourt from Po). 3 ‘top [s] Oo >01 ie 5 | | | Peloumione the pola angles of ports curd sat them wi oud ef polar auples he Bokeh og pls | ‘ m re yc wi fs | we \ ay ate | . of | _ \ he @ Po haw hugh poles angle: - Sout ax per rneceasing pelos angle with | fespeet & Po Push omenemum 3 pocnb & stack | Po, PriPe b Steuck | | J o S Fa (+3 lo 2. © > Comudu Next-To.0p , TP Pe and the tun ike making. | n | if | @ Ps, PL wo te mwa vs as w ao e we " YS LP, Po Be & wight tum he Ge ® 80 Popts) eta ws bp, Stach becornes a aa _ ri Po. | As 0 taght ten - Comeicteu the Afb Pe Pe will | Cone ingcde the be vik. £0. Pop: ti Po ext wot be au clment | of boundary /comuer polygon @>Push (5,5) we oh yt oe ‘ a . ki na” A Comscler Z Ps Py Pz — Right Quin Pop ( Pu).-So slack Sls[> t | | LD Pe Ps ~ hele tuwn - Pust (PbS) aE Py Po Re heft tun - Puce! (Pr, S) ZPGPr Pe — hefl Tuan - Pasi 8,3) SPE. x fet Pa, bh fo Zia vs Py - Right Tuan - PCN) “PL Pel te | Ped dre Bile Abert - ee Por (0) (3) aa: Forth) ABOIEBA ZfaPePs - hee Tum - PUSA( Pays) “Tal tel ts | fr |B [Pol Fifi Pa Re - Right Tum - Por ( Fa) ZPio ty Ps - Reght Twn - Pop ( Poy Z Pots ps — Right Tum - Por ( Ps) Z Poa — kept Tun ~ Pus (Fo, $) Z. Pr Pos - bolt Tum - pus: (Pm S) Z Ro Py Po- Right - pop Pn) Z Piz Pio MS - heft Tham - Puse (Pia) Fimal Slack & Stock elements form bounclay element Hence Feral Comenoe Heel 0 | tsi amo of port So Ol) ; © Fencing polaa arng 0 eat achach (abe OC1) = constant lume Soxbiong thom $a M aeymontt - o(mlogn) Uses ernonge OF heap aout : 20e oop - O(n) ‘galiyg © thule loop thule loop wndergoet apaiegadls Orsalipe Fou Pop - Harcomuna Pop = No: of push So No: of pops £o-1 08 Po, Pi cannot be popped So Pop > oln) So Foi loop as 4 whole Oln) Onwewhole algorithm O(mlogn) = Houmtaios a slack $f candiclate pownb. tnseewh alt pb lo slack and pops owt pl that & rot qorler of hate. hen Algm lumemata slach S cnlquns the unlles 4 CHCA). Wi Counts clockane glu al appecia of boordony Anput = Set of pounls & whe nla)>? Topls) = Retwun pt on lop of Slace Next tp lop(s) = pe ore entry betoco tepls) Without! chansmc | | daewis Marcy hugormin : | Computer the Comuer hell peor a queen set of Poin rung 0 technique | Called peeckage corappinng ot ggt eorapprng- Workeng : 1 hocate the point Po wth munimurm Y eonolimette & hot A be the hoxigontat Line through po 4 & clearly langet & euts) | at Po. We oKunt k froma (ye @ Aught. Poxfoumeng wonaapping & bocate Pr whioh a hang smallest Counlerctect dre angle usth 3 Repeout corapping at unas w teluun bw point Po | Algoncath on [tA base fo w selected, the port wth anencmunn ¥ Conolenate tn Case Of tev, Select the Left onoet poent le. The out conucr helt ouertiirs haw least polar angle wrt tax hentgenle tay from fe Mecucus t Counls look wre durzclon tp be Occurs. sebeolr de farthest pexit ie Verticrs Pp, Ps .. Pe ur pecked Sctaniarly Ye > Yona | Sequence Po,P,.. Pe 8 Called tight Chas» of cola) | % choore keft Chan & CHO) slaxt wet Pe Ln, Choe Poy as the pocnt wrth least potas angle wrt mnegatias tay | fom fe - | haf chu Yo aught Chav Acnalyss : | Algonithan oporats om any one poort that on the hull, say the lowest | €8 tee of hut a found out count clocbense cusettin . Nsseme Per Pes |e ast 2 ponds added on hell, Compute the pout % that omaxoncie the angle (Peo, Ptay,q) - Fount ga found out tm oln) tre | foa cach aueslen P belomgra bo eHc8) tt lato ol) - % Compan polu ange | 0Cn) = To gma maxcaneem pola angle ofp) - Totoul tome |g cna) has A unten - Running Gme a Olnh). | phe ollogn) then algorettrm latix O(@logn) | Stilt fasta than Gohoms gam Finping CLOSEST PAIR OF POINTS ‘gen pe ow 4 2b plame- we hone to fend the Closest pau of pomb ond getuer am pornts i a 20 Plame Pil yo) b> ty 2)381-.% ‘ ro) | (uy yap | W2tsh b fend out Fond j ralues toith amearioncum Kucliclean du Gower Kucleoean Dislunet =] (ae 2j)?4 Cye- Yi)? = OC) thane bm pounds aur the , Thon we haw b euotuole C2 paws nd find the oncnimum =. = OCD) tendo As we haw b run the for loop o-tinmes bo fond the omentonuim dutanct by Brule Fovce Algm | feb c Ome Demensfonal care, — lunwan Pour Geen pons On 85712, 18, 19, 2¢, 32,2 Henemem duloace among thom : Sol tom so 25 @ 12 & M 28 32 - OCmlogn) traltolly mem <— 0 Butane 2-5 mines 3 5-@ Mm 3 3 PR wam£ 93 4 mn <3 12-0g min <3, b mb MUM < Distance Updake - Bg mn 3 adhe $2 he the closest pau tn send hal. ~ $ . wth dulanee > 4 . ane bre between thom such thou elements torch au lure * 3 26 from thew “Herge: wotth checking unten nen boidu \ bae 4 any pu o hawueng muon ° 2 du tance Ics Se mune, .S2) + Suppoue pond g ar povitly the clovet pas utr p lo YC ¢f dicurdeng lac | and 4g on tught - Clesse bo deaucteng kere and then Ub bo be teyer | dnd thor @ a pont my worth 0 9 band vane | thom 5, 80 haut & chech | any poets wesiceeng of & to both sol | | If ome port tus 0 Shup ut GD search for a poont on Stup Reght (SP) Peay) © Sh. Then Suanth for point Sp wwtbh tn romge of Ys RS Thaw con be nou tham one poal the xuct ong - to Find tte no. of pank = #6%0 of poi | bt an | 4 a pas that aud paul Gen the veclongls | - |! s lep 5 Tha helps b mabe Ol) alg Hege algouthon ° aft seolern abso can hae on powil - So Sues at Gn for cach poate distances hewe be eheckod Closest Pau Cb, 4) be Lyft ads Frond the clogest pad & P[U.. x] Souleol by % cokids > aught cnaler Use Huge b mabe pf t..2] gould by ¥ co.ouderat Ctosest —Powi (Are) | 4 8g TP) <2 thon robin enfumely > Ie only one pou mid = Ua 2 Md x = Plmd])-x; df= Closest_pau [1, med]. de» closest - past Convedyy,s] dutta = mea(at, dy QL: Select candiclale (l, ond , della ord 2) Qs geleot. candidaleCanidst,,, delta,oudr); dn> celta on( 91, Gr, dete) Herge(t, amsol. 2) Retoun “crue (len, dt, de) | fh Ten) w the tome Conmplercly ftord the closest pact TO)» For Land tus Ten) + WH) +1(8) + 00) foromege = 27(2)4 000) F oCnlogn) Panning Teme 64 Dieu m Conquer method Ten - 27(2)4 O(n) Diwete: A qurtiost lene which bu eel: Pent 2 cele Pranal By with Qo % 2 No: of pl om ut Auon Lift of lire L anol Me tught of ¢ ; N2 Scuba wtth a coordinate 65 pounls Ye Soutd osouy uotth Y covudenaty af punts Duude X nln A anol Kp % per and Pe ily ¥ Conquer» Mabe furo cecerusive Calls © Find clo sek pau of po Pe. Use Prard Ms YW @ Fond Clone pau of blo ov fe Up» Fr anette Ya ake Closest pau Avluned fr Po Sa > Closest pouk azlouned for Me oS 2 men (St, i) Aunbiow: closes é pou may be gue corth ancen dulawer J 01 @ Paw coheth onept 6 Pr and othu 1 Be lg dlelurmnes the tale obsouu of thou o paw of pounls en S Unel avound the tors 6. $eo bolb amet wide o> 9S wttde malo! Slup wath cents tine f- 1g fend Sach Rape « ) Ouole YY tai ete ine oe tina » bey (D o pomnb wh a oN Met eda cols cbesCancee fue pe there 2 pout, ck of cloest pau deslanct 5” Cues cut pout ef, po 2 3) hated that onoains thes w & par ets with ty dularer

You might also like