0 ratings 0% found this document useful (0 votes) 8 views 10 pages Advance Algorithm Assignment
The document discusses the Longest Increasing Subsequence (LIS) problem, a classic computational challenge that involves finding the longest subsequence of a given sequence of numbers that is in increasing order. It explains the dynamic programming approach to solve this problem, including the algorithm's time and space complexity. Additionally, the document touches on NP-completeness and provides insights into various graph algorithms, including the Ford-Fulkerson algorithm for network flow problems.
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
Go to previous items Go to next items
i> Dynami Prtogrtamawa tang.
Guestiou +
The Longest Inurrosing SubsequenentLIS) Prioblum is a Uassit
Comput Unallenge Fhok vequirty Hading Hw Longest possible
Subsequene OF & givin Stayton of Dumber Sued Hho Has
Clements io Hu whsequenbe |xte to sttiudy ho ues ing order,
Given on fnpu} extrtay Lio 14 25 3), tol rie].
An ineutsing Subsequent | (2,94 Av Toe (257, tor).
ome Longest Ineruasing Subsequent, hos a Ung th od.
@ provide o sep by HP Eptadatiou of How He
Lis is determined in a given sequen of numbers 11091205
3.4) Voi] Using dynamic Pring rom ing.
Auswert i-
The TetuTveucee telatiny doy Hue Longest
neces ing Subsequny Prov is given by -
0 iE feo
defi = . tedeG
wax 4 de, OK ges vactcacth rer | btuerix
whery SeCi] vepriesenty He Ungty of te Longest
ineuasing Svbgequenty or index f-
TuiHliratious- we imtolize a DP otttiay Where
cou, elmemt detil=l - reerusenting Hat day
Cument Jory ak Unt & Subsequene, of Lngtt L.
Iupot entry: [102 9, 2,57 3, 4 Lot, (e]
DP ortttey :- Crete doh toda tdAs we Prrouss he attoy Htowm Ut to tigub rwe will
updete Huis values by eh eeking if woe cau extend subgequvoury
Hrow pruviouy ements,
|The following Hb showy He Cowputotion of Seti tor
(au position (my Ha given extetay t+
Col ev latiou 4a
Prituious Iudiens
{uty | Velue VSed
o| Jo} 4 Bose care
L | 9 i No Pruvioy Cument < 9 |
2) 2 | L. | No Pruvious cement <2 |
3.5 2 wax (L) dPRTHE2) 2 422
4 3 2 wan (1 rdpiyrier) 2 c
5g |g [MMex( i, deetare2 drt | ss gy joy
| | 3, dPCuTti=3)93 |
6 tu y mex (1, deCo eles. decrdtte2.| ,
APLrdtas 2 dP} tied. SPH] -
| _tiag sdpteseitio
ig jap | 4 | mex (1, decederea -apcrtesse 5
drcattie2 -dptahieg-aecdy| 7 =
| 23, cy ) dpe
3, dPLsd HL 1) a on
Final &P arrtoy
Suu | 0 1 |2]f3af4|s [e x
Vatue do go [2 |s5 37 Aos te
decid 4 1 Ti faepors ThrThrafort Hu Ungt of Har longest ineeugaing subsequener ts
u.
We Cau Oso Beeomstrivee He LL by auing back, Te LTS
tading GE index Gltonos Wngtu 4 Gard, witty Pruviouy (ndex
5(9) Whius hoy Ungtu B+ Ludex 5 comes Frtou index 7315)
ty index 4697 wit Ungtu 2. Tan index 2(2) with
ungty 1.
So posyibu Ls ty [275.4 tor] oF [2-3 #, Los]
TE we draw Stow index J, possible Les & ante f
(25/4/48) or [273-4 18]
@ Ameu went Hu longest imeruoring Subsequene CLES)
Probum in pytuon + Preovide Hu pytuon Code for Solvin tfS
ud exploin iby Hwu aud space Compurity.
Pytuou Lode
dye LIS (muy);
Us len (mums)
des LiFn
for i in vouge tn):
for 4 invauge UO) +
th nowy [31 < moms CI
Slide won (dechd det i412)
vetortm wox (de)
# exo plu
Ort = [l015/27 5,3 ¢F, LOLs 18]
Prtint (" Lengtu of LIS”, LIS (are) )Tw wom pleri by s+
stu, Olgorikuay used dwo Nested 100PS +
Tw outer loopy YUMS D Huy oud Hu inner loop tous
up tot Hmey foo tour fy
oki buss
ot)
O41Lb DEO eimet) = a
So total inner Looe OPE
Tuiy is Ol)
fuside Hu inner loop rH operatious Hu OL)
Overtal) He towptarity ts 0 tnt)
Spa LOM PUY Lys.
The OUgorvituur Used & dp artmes of Bieen
to More Tha Ungtu of Lengesr imeregsing Subosequente
Ob COU inden
Thuy, Hu span Compuxity is On).| a. . ‘
| Give Hu diveued weighted grtagh sporty Biskstre’s Aigoritums
4o Find shostesb patu Stow Hu start vertex to Hu gout
Viva in Hu fttaph -
wf ‘gous [geet one et + equstité oe
0 S S50 ; $9
Aza. Be4 fy By
Cc%) D238 Dy By s bg
Dy arial By Ey,
By | Aed, tclordett| Eye tgs Age broe Pay
|
tq | Deak, E212 | Age Py He Kio Cro Dy Dar Ea
2
3
y
5 By | fet Hag Keto] tp Ag Fe Ug “Ho S10 ae
6
ZL Dy Ory Ena O42
Ay | Ssi25 pee | Fz He Og Ho C10
Hg Dg Kav Cro Pay Puy E12 San
so FR -
9 ug Kee Dg Kg Kuo Sto M1 Py Era Sse
Jo oe | E29 ke Gg Kio Cro Prt Ory Exo “42
tp) be | Geto Ey Gyo Kro tro Per Poe Esa Car
to | Ey | Feta ekets Hel) Guy Kio Go Pn Oy Sin Fua Hie Ge Kar
43 | Gio | - Kro Cro Ory Ore Exa Fur Ht2 C12 Kas
$8 shortest Paty from Storf vertex fo Hu goal Vevtex
$5 aAIDIEBH> KG
Distaue 2-10Guestiow 3 t= Nebwork How
© consider tne grtaph hor nding He wari mum How
in Hunetmonk witty Copacitiey between modes . Use He
Ford Fulkerson algovitwm +o solve Fu Probl -
myguiated peli- f9V5 Wo &
boltuuenk - Lo
Resi Lual Network
Auguicubed pot Sata vatot
a ute L0
oHlane Royidual Nerwerk:
Tutal How = Mox How= Lo+s0
220
Se{svy
TeAvets us, El@ diseasy Hu CHHiueuey of Ford-Fulkersou Algoriruy.
Whek iy Ha Hew compuxity fn ese of ving GI a
Hu aug menting ParH Seortee- Me Huody
Tu Chfiutuey of Hu Ford-Fulkersou elgorituuy depends
OU Mow Oupmenting potus oye Umonceu. Thy Huw
cowpurity iy OC EF) Where fis value of Wex How,
Whien on be Very large if eopoiHes ove larey ov
ivtatioual. Ly tu worst Gye! it Moy toe exponeutially
mony ‘tevetHous
THe Ford- Fulkerson Gigavitu breome Much More
tHident when OFs is Wied to feled kugwenHng Potty.
When we Ved Bes is ta find tue Shorher Qugme nk ng.
foray e Te Clagett is called Eduaonds-Kane @lgoritu.
Te quarromtes & potyooutic| tina COmpurity of — 0 (ve)
atuly is bese, BES Limits Hu nuvaber of dugmendhruy
Weedtd 1 making Performan Prulicteble aud efHeieubGvestiou-4 . NP Complereuusy
© Expleiu NP Hu Hawiltoniou UfUo Prrobuuy, Then, Prove Fuse
Hu Uowil tovinu Oye Prrobuae ty NP Comeltty by veluding iF
Frwy QsaT ertoblim -
Auswer- Griveu au undiruced graph Mele). does Here
txigh 0 CyUle that visits every Vertex Cxadly OW aud
Yeturtus to Storting Vttkex. The Hamiltonian YUE Probus
Ty Hae dteision Oriobus -
Hamiltonian yee Priobuum iy NP Complete s-
= (x W 4") A Chv tiv %)
&
4
Sima HHL ore He edo » WE Weed SALES ES odes bey
Cou Ori Mo
HL
He
f} Huu exliy 9 Howittonien Cit in Hue grap @ -
a Th Hraverty A Fro ME Fe igh 7 osrigy % © Trive
eh H Hroverrser 6) tom riguk to URE assigu 1 = False.
Thy Ginaph 1 hey WOmMiltonial Yee (Hrerru is wove tues
ome, buf wre fs OneSAMY 5 2m 4 By by Ay TL 9 OH > EL FAL
IBM Om May Day OAL > DAM Hy POM
thy
PAY By 3 Oh) 5 boty 4 2hg 9 By 9 Mg 9g FOF
Hy 9 By 4 $y 4 EDS.
Mol 12d
wycl + he
*gc01,% 20
Q= (Hv Vag) 4 hy v% Wks)
(ivivo) A lo viv)
= LAt
2k
Veviied iu Poly uouiel Hume,
Fsar S, Homil bomiay vy clo
Hamiltonian cyele iy 04 Uayd as NP.
Hewiltoulan wus iy in NPt-
Foy 0 Guan grtary Gilve) . We uy cheek &
Solutiou (eerHfitate) im Polynovtias Hue. Hyak eoey
Vevten Oppeers exourly one od Mat cary Longewhivg
Is au edge 0+ @. $0, HOGNP-
Sivek Howwiltonian eyde & iy in Np sud Hawi ltouioy
yele iy 4 Word os NP + $0 HOMINtouloy eyele fs
NP cowplte -© diseoss tu Siguifiteme Sf Np tomplel mess In reo, World
Probumy- How lots He Comuphy of NP-hord priobluny {wnpout-
| Rigurituvtie veseartur ond Prieur tol cerHetous ,
Ne-compltencss Clossifies Prtobuuny Hast Lack cHideuk @your
SoluHiowy UUlyy PANE. No-towpleteuts is Significant becouse ih
fdeulities probums for wits mo Kuown Polynomial Fim
algorituon exist, Yer Huy opreor Hruquentty in veal world
GpplicoHous Suen oy Seutdwling, YouHnE, OPH uizoHey
Goud FeOUNL Allowwtoy~
Kuowing O-— Probl iy NO-ComPlty Utlps Yeseoreuers avoid
| walsting Hay} Seon wing doy fat thou Agerituwy aad
insrad MoHvates Hu uye Of Oppetoximatous , Utuvishey or
| Apociel Case ColvHous. NP Completeness Fells Us Huet tousoud
OF yraturel prebumy OL equivaleutty (n UHiwlty. Cr one
Mos ® POlynovatal Olgrvituan 1 AU do.
The Conupt of Np-uardness Atco Qvidey Olgoritu uric: Yeseortey
by liguliguting Whiehe problems Org imheruntly Ultiet-
fund Posting Tac developutent OF Preackitel Streakegios Hante
| trode opHwatty Fy ¢xueuey,
|