DAA - Unit 2
DAA - Unit 2
n=5
3
ro smarge oponthen ts
whichaan be cwiten as h)
e slitirg tie
b how yau ane. subpotan
(valus)emnts in te
Master's Theoreng f0
o Didhag
Lone of tla inetod that a appliad to
alaulat tine tornplities t olgorittt
Masters thoore plidon eaeAa
oelations.
applied on deessing
yT can be
dividing ecuericg-tn.
Case
Llog=
3) i-f actd
Tn )=6(n).
PRoot: Maste-heor0M
leulst conploxity analyais
Ca
b2 d
ar 2
!. eln'ogn)
Tn) e Cnlog n).
Merggsot
aEatution Wettod (hachuoaN
MProot Jaig Subsitation
-T22+2-1
+2
k-z
2
k-h
-2Tlta2-3
A
+kra
-aT(aed) + a'|i]-(*-J
ar(aha)4 a.2 - [2-1
Gersral Representatiog
subs =k |
-aT(2)4k-(-)
K
wheve T ) |
+|
where na
K= log0
hence- pyoved .
uick s o r t o
88 744he
iepivotprs! 11 4Tha j-
4)33 J 85 22 4o qo 60 q9 TT 88
B3 <4oTue t
35S22Te j-
P I1>22 false
33,<225-false.
33>22’Te)-
Thie’t+ I>22’fabe
I1<22 talse
33<22
bted list
ft
baltt 3335
Zonted.
22.
Seard
hat 6o 49 S8
4fase
6o90
a9<90 >false
i jstop swap
40 6o 88
99<90-f
270-T-
Suwap P R
40) 44
40y T1-ST
T-9f
b0>7->f
22 33 s5)44 6 1sto|49
n1 ’ Base cordition
Tn)
gearches dera
hatfs
list is Splitod tn to tuo
Recane Reatien Dao)
Germl-fo)
2T(%) tsn
BaseCerndifsg
(n2
F 3n-(ot142) 4T(n-3)
Bn-(ot-Rk)+Tn-3)
2
4Tn-3)
Gehetal-tom
kn- KikDT(n-)
k(k-)
2
T) 1 assum 6-k
=kn-klK-1) 4T)
2
-(n-)n-n-i)(n-4|
o2
nTake
Taka teutes ue bound
=0lo)
Eneny Search
Condition is ist emnb must
be in Sor ted ordes.
’ (og) ist with n eloments
Search keuy 6
Apply diide &lopquey
12
2
2
ntmicd"
is Cormpomdwith
Nouw key
Parts
divid tnto tuo
is
Now tte list
Jowto mi
mid4tto igh
mid
8
5
check Key <mid. wo are
en left half
soarcking
L
Cempared wit alo]
KeLy is
b= 5 fabe
dinded on to 2 parts.
lists
2
low tomid
Coetatns ony one ament so
ist aments
cirety Compare
66 element -found.
Tacl b Searehelomunt
N8
Soarch
Best 2) wcst a) vg
Best Gase ’ search elorment is egual-oeo
Vatuy t iddle oloro
(e) Senrch &. m = Lowthig h
2
m 041
2
aCs]=6
Seavch ele at3] ound
. Bestczse. ol)
worst case. ysoach elomert is pESe nt at
eitfer bog iningtheolonaovauy,o end
the anuy tac
le) H tae. olevunl "is not preatin
thay .(o)
arny
ea) seac h elament =2.
Lstconaiso0 m Lt4
-3
middls ele f search elameat
2rd cormparison
142^H
L Search than tmictHh ee so
M0to
2
nCo]= 2 Seatch ele :Ctomentfoud
Confaiten divit elorst
ho oelornants diride
|’ 8 N untilsize
airays|
8. ’ = 2.
D22, no e Comparisons
Birryseach
Ttn)=T(n-Hc
-TRJtec.
n =l
k oga)
T)=1 n=ak k:
n=2 ide) T()+lo,n-c
Take toc en both -14 loq20
leave constcnt vale
N-9loq
HS3
Onc-dirhensien al aray ’ which may contaig
both posi tive & nogative integers
fnd to Sum af coniguouslongest
S nunbers cohich kas the }ulavnySum
(e)
-3 -6
-R-56-2
Apply Divide&conquer
Larget suboray un=1
|-2.-5. -2-3
RSS 6
No2,6,) (s-6
c$s=
-3 S-6
-2-66:2
L Ls Rs3=6. Hals,-34)
LSS-1 RSs-5
ox(5;)
Han-2,-7,-5)
geanltay-t mar)
Tt is a nocursive. mettod e ike Gontlortty
Cun be exprssed. as
follouoing
Tin)= 21%)n
Tine Conglerity : olnlogn)
Mastere theorem
Tn)=2T(n]2 )+nd|
Q=2 b-2
en log n)
13 mid= otf2
|
2283|2 mid =4tG
2
-min 2
maX =83
tuo subprb0ma si,
Reauvsively solng Compansos to get
22
rwaking
2min.
the ovevll mk
Recunene laton
Tn)-zra2T)=6
toreelerent no
T2)-1 Compisen
alomenb bN CoMparin
26
a2,b2,d o
azson)- 6(n)
-eln).
Sabstituhian otbod
ngk
Tn)2T ()42
=a[at nn)42y+2
Assume
k-l
a'n a(i)
as2,T:2
nk-1
2
a(2-)
0. c)42-2
n4n-2
2rtn-2= 20)-2
2
Cn)
TG)er()tan
Lstonploitysetr)
delaz1 tazs)bi
(be-ba) d=(apas2Xhytb
d an
dytds djtdyt
hmiuo Con be combircd with
- strassan tec
divde &Comqer srataa
slps
obtaincd
H|| tics o 2x2 os deu is
Q. Vse shosents foormula te Cany ou
212
ultiplicoton
Corn bine e sults to got iral product maty
8.
is
RecauutA cqn foo strassen mati
subs i=k
n= k losn
2-807.
5 2/
a 12 =5 bzl0 b2) =1
az2-2
+a22) by (512)1 =Y
d2 Caz bi
alb2-b2) 2lo-1) =
dg - lo-1) =
(baj -by)2
d, oz
-a,taz) ba2 = (3+5)|
ds
-as2) (ba,-tbi) -(s-2)(ot)e3
d-laz
Cy - dit dy - ds tdy
-9-2-14 3-2
C12 d t 5 2+ s5
C2l dty 7-2 5
C 14322
:c-l2).
es) 2
463
a aj Be 1 I12
3 2 I2
311 3
Bol
pl
di- (A tA 2n) (B 4Bsz)
6414 428
31
10 16
d2 (A2jt A22)*Bn
d = Az2
(1)
ds - (Ay-4 An) Bz2
s 21\
(BBin)
2 -3
)
dy (A1p- Aaz) (B.,+B,,)
dg tds
AB (dtdy-dsteh
dztdy drlda-d2tde
3
(15 31
detdy =
81
d,tds-dates = 20 18
4 4
3)
AB=
6 12