DAA Unit 1, 2
DAA Unit 1, 2
2] 1+n+1+n = 2n 2
k
bgt
dme <omylety (for iz0; i<n;itt)
(1+n+1+n
"Preauenty
max ime
(Gü) Theta (0) - Yavnege cae
"eost uppenbsun
an2 +n cgn)
An +n cn²(c=1)
an2+n7n* o not satiefied as
LHS > RHS
ane +n 612 (C= 2) K
&n2+n <an
ant + n 3n2 (c=3)
an+n 3n2 RHs> LHS
n73n2- 2n2
o(o)-fupa
Leatiatid as
RHs> HS
(v) ite Qmega (uw)-fony lou
boundy
Jast uppebeund iw 3.
Qn' + n > Cn
Recwvence Relato
Lustitution
- itvatigw
Recusion e
Mastis theee
Substittio
TC n- ) +n
K put n as m~ .
T(n-)= T(n-1 -1)+n-1
true fonr n
2
geatest lower boud
Tn) =T(n-) +lg n,t n 1 0
T(n-1)= T(n--)+ degn-1 (put nas n-i)
= T(n-2) + Aog n-1 afler substitutim]
To) = T(n - 2) +egn- tleg
put n n-2
Tln-2) == T(n-3)
T(n-2-) + Aog(n
+logn
T(n) = T(n-3) +togn-z +lognt+ gn
T) "+ag 2 t deg 3 +Aog 4.)
|Aog (axb) daga+tegb Permea
=|+ Log (2 p3 4-.. .kn-) n)
I+logn") Tln)
) T(n/2) = T (n/4) tc
T(n)
= T(n/4) t2c
put as nJ4
Tn/4) = T(n4) +c
T(n) T(n/) +9c+C -
= T(n/3)+ 3C
= T(n/2k) + kc
put in T()>\
T(n-*)+ (n-k-))+...n-)+n
T(n) =T(o) (n-(n-1))+....(n-)+n
T(n) =| T() l+ ..... (n-1) +n
T(o) + \n (n+1)
2
Tln) = 4+ (n(n+)
2
3\-01-24 unit.
Recunsio e Methed ’
ude and cequ Quick sort,
Mege sot
Cven (T(n)) = T(n/2)+ T(n/2)+n
Ad whun moe han one rin spanningtree
Quick sort
selecrd,eaehh element
A pivot element is
e
6 then divided 1nto two eays ,
a ut) as eleents shale
element nd anothy aray
nl4 n4) than
has aements qeatw than pivot
element
8) (n/8) ) 8) (9) () (N2) (ni8) Pivot element ean he sected from
etther det or right .
Jog both sides
abc.....z
LHS) f pivot element is'o, tat scanning
from z .
Tf pivot element is 'z', stant sorting
RHS from a.
1 =0
Aagm - hdag2 2 3
3 4
agn
ngk0 42 6|O|3|S
136
4|2\s|
qen- T(n)=T(n/3)++nr(Qn/3)
426s3|6 >]4|2||3s
Nous pivot will change to to 4
and milas wethed eie lae
Glewed, nt we get this
[|2|3| 4|s|61
Probler
divide
8n
1/a 2n Subproblem |Sub problem
solve subprobiem
conquer
So]n to son to
subproblem Subproolem
Let
Solution oblem
K
Date - 06-02-24
Menge Saft
Prims (MST) -
5
62 98 3
12.
(Another version of Krushkal's)
1 2
214 T6 3|s|8|9 3
|T|234 568|9l e
D
3
Pims 5
3
3
Fomula
Tree
tor ealaulating shaming |
Kruskal's ’
A
(Disegnnected
it
(9t shoudnt be elsed,opened)
is atu,. t has tobe
Now, 3 +4+ s,+2 +3 +4 =QI
Jotal Writ 2l
complerity olelage)
Condition for MST
Vertices =V
Knabsack Algoritn
JS (D, J, n,dmax)
obi obe ob3
25 24
int k.TS Ldmax]
for i=1 to n do
TS iJ -0
uudy tor puotit 28.2
for i=1 to n do
AS + 2 /15 X24
k=min(dmax)
DiJ)
1S+ (0 x 24 =31
then TSCK] =JLiJ;
yreedy for both (PIW) - i =i+1;
24 +5 x 5 31.5
Dijkstua's algoith
9 We hawe to
Lal start
14 tyavwsing
Iaplemurtation o Mg Sert. 15
from the first
node ibself.
MERGESoRT CA ,r)
Source Destinaio
2 3 +884 La
8 6
(mEROESORT (A,b4)
meRGESORT (AAt,) 14
meRGt
(A,p, )
make it o, (4
and MaKe
Yest the to
nade Ou 00.
(Used n
dmax =3
1 (,2,3, 6, S 20
his a manimisatiÝn pUelm so
the puapt n (,2,3,6,S
4)
deseendiny der
6
Jate- 13-02-24 eritos
BFS
2
o
(FIFO)
Destinatin (2 3
Souyce
stasky >(LIFO)
(a, c)
a,c,b) 6 [DFS]
(4 S
a,e,b,d)| 4
2
(ccb,a,e3
ac, b,d,e f)
olv+£)
A For 3 2 ) 391 + 2
A ACB 5 4 + 8
12
AC S
ACB to foy 3 4 ) 3’1 + t’4
)5
D² matix 9
4 |2
2