Professional Documents
Culture Documents
DAA Module - 2 (Part 2) (S Mercy)
DAA Module - 2 (Part 2) (S Mercy)
Anadys
Best case, occuSS element is presen exacl
exacl al he
h e
loy
Cenbe dvolim he o y inlo equal povs
Tn) n-
TPla)T (A)+nt o pavBkon n elarnents
T(n)- aT ("/a)+r
a aT ()+n
a'n) an
+in
a'n
1ake dog on eth Sieles
i les hs
T(n) nlogn
TC, Tn) -
A(no9,")
WOYst Case
Aeach invccohon c) the proceeluve, the curenl awa
is pabboneel ino 3 ub cs
ay Cwith one ) dhem being e"phy
Occw if al he elements are Gogpol in scerol'ng orolen or
descending Ovclen)
n=
T(n)
T(o) +T(n-1) tn obherwise
T(n) - T ( 6 ) 4 T(n-1)tn
T (n-1)+n
T(n-2) + (n-i) +n
Avenaa Ca
Con. nau
may hot be exactly parbkoneol nt
3keues as in he cwoYst Cap . oe
Subamau oy may hot be
Onging o m 0 lv h-
me t 301 ! pat
B 0, 08 k-1
k-0
1me b sost vght pot
B k), 0B h-
Ne te ms on ight UB-B4|
h-- -14 1
n-I-k
at he
whle valus rs placael
nanag, hisghet integp
end be gn: u
,
ota no elcmenh (hi)
Time unit to pavbeton (n41) elcmenb *s n+I Bme riG -
Mspeyb n_
n T(n)= na1)(ha)tT() T(n-)-k)
-
(na)I+ =D
T(1) +T{n-)-k) n-1-ta
=)
O,),a, n-2,n-
n-1-(n-)
n--n4
-
(h4) (h--o4) +
T(o) 4 T(n-1) T() T(n2)
T(n-2)+ T( 1)4
T(n-)1 Tlo)
T(n) n(n+1) +2 T(o)+T(1)
T(2)4 +
T(n-)
nln+)
Replac by h-
n
n-(nJ)
nT(n) T(n-D(n4) n
4
n(nt) n(n4) n(nt
T) T(n ) +
n
nt)
Raploa n byn-
T(n-1) T(n-3)
n -
Th-3)
h-a n-
T(n-k) + 4
n-3
n-a n- m)
T(o)+ 2 n n+)
2 dk
2 (nai)
og, -os 2 b
T) a loga (n+)
T(n) (n+1) 2 log, (n+)
-
CCij)= Ai,
K=
k) B(xj)
O3)
Divi and ConGue,
AsSune h isa a, Ce) dhere esls
powben a
hon negakve
tntegcK uch that n2.
n is not a
powen u) wo dhen enoug h OWS apd
Columns
umns 2eoS ae acdoled to bth A rd B So that the
An a
C Cia
Ca Ca
Ba2
C A B, 4 Aia Ba|
C12 An B12 t
Pa Baa
C , B,taa Ba
C20
32 P2, B12 Paa Baa
Lmanine that ond B a ench pavbitioneol int ou
Tmanine
Squ are Bubmatke, each Bubmatry havtg omensons n/a
10
n 3, above OYnulas ao Compuled tusing C
formuks, heeol o
lo Compule B fov the obove
aebora /a matdes
can be aololeol tn
mabsces
Since tuwo ala %
two
se
se mulkplrakos Cnd 18 aoldbom 0Y Subtra cho
-Pa +Paa) B
R n B12 Baa
S Paa (Ba-B)
T (Pn Pia) Ba2
0(Pa -P) (Bn t Bia)
V
Pa Pas) ( 3,t Baa)
-
C P+ S-T+ V
Cia R+T
C +s
Cag P+Re-0+u
Yequre 8 adolboas t Subtvatkons
b n a
T(n)
3T()+an n 7a
Compae
C P+S-T+V
=
( 4Oza)( B,t C22) + P2al B2-8,)(P»tPia) Baa t
i-A2) (24Baa
ABn +Aa
Anas
T) =
T(n) -
7T( "/a)
=n
2.81
:81
TC, T(n)= (n
MOYe
Move eMient o Veny ange Value n
Example
B 5
9
6T
Tmplement Stvasen's mati malBplio kon on Aond B
AXh mabx, Bubdeviel nto a Bub motrire
B Ba Baa
(3
P - (AntP2a) ( B, t2a)
3 ) (EJ )
J
18428 30+42
30 th0 SO+bo
: 13
30
([-)R)
6 6o 76
45433 30 455)67 9s
R- Pn B1g-Baa
20t 3h
1610 1613.
S 2&-B,)
0435
3S
6+10 ISS
018 1849
= (Pa-n)B t Br
18 0
354 s +h
3 88
39
59
V (Pig-92,) (%t)
(C: E3-1 ) (n:)
-
-3-18 -12-I
-13-9
-a6
f-31
- 55
C, P4S-T+ V
36
ss
35 37
66
Ci2 R4T
a19
16
30
3H
+S
Can
8s 35 41
C68 87
134
Cp
2P+R -&+u
88
to 1o ho 51
S
S8
Prpdluet rmatwr C 37 30 6
34 6
fc C1a
68 87 Sa
Ca C29 0a 34 S8
35 31 30
66 99 3 69
68 87 Sa a3S
/0a 13 H 58
dvantages and Disaduanlng_dv'e Ond COrque
Advanloge
Idicll pm blem bwken deun inbo ubprn Bems ored
ePctent algoithm
I also tuse» memon ache effectively, eDon is
the Aoheo
ohn Subpvklems become Simple erough, thuy on be
COthin a Cache, co?l hut havirg to aocess the 3loue man memons
DFsacsanages
are Ceakeo ord necol
B u bests
anGe
AaG numbe
lt he pu eNseel
decuxsive methts , vecusion is 3loce
a make uSe
Ond Cmple
3) Sgupsts Yeclcing
a problem instarre by the Same
lopoloqical S0v
near ovolen ) Ventex
DHeere belwon verled ernod und'eelrd yaph
he adaoer malix diveted paph loe nu
have y be
Bmmeic
d Gn
eolqp in a
d vected eph has
ut One (rot hwo)
Cvepondrg naes i'n the dpaph's acyacerey l s
(a
tree eolge
bock edag
> fovwamd edg
CYOSs eqa
Depth sgeavch
Pexhrs a DFS raversad and note the ordo
Vetice 1s impoSSh)e
SooNce Yemoval mehod
basecl On a dtheel impermenlakon of bh cloc and
Conque lechniquw (hy One)
Repeatelidenq in a
emal nin
oghaph a
Soute, whch fs a Veslex wdh 0
Ording edges ard dolete i
along wth ad he edge
Several Soures break the ke
outgein rvm it IP dhane n
3
oo
3 o
O
so O
Indegre O 2 3
Visted
Adjacent Incleene O à 3 4S
O0 a 33
,3 OOO 3
0,1 3, O0 0 O 3
0,1,3
0,),3,3 O0
O
0,),2.3,
O,2,3,4,S
Oulput ts 0,l,a.3,A.S
Vis:led Staek adi aount Vevte x Poppeol elernent
b
&.biC bc,d
ab.c.d abiC b.cd,g
a.bC,d,9 Gb ,d9
Cb C,d
ab,C g.d
ab
a 3,d.c
3.d.c,b
a,b.c.d,9.e 3,d.c, b,a
S,dc b,a
Gsb.c,d.g.e,f 9.dc, b,a,e
9,d,c, b,4,e, f
Popped eerment is 9-d-c-b-a-e-f
Topolqtal 8ovt -e-a -b- C- d-q
pp
Applu the DFs basel
alcorithm to solve the
topolegrcad Svbng
Prchlem hy the
ellowfng dgnaphs