0% found this document useful (0 votes)
23 views8 pages

DAA Unit 1, 2

Uploaded by

lavthecoder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views8 pages

DAA Unit 1, 2

Uploaded by

lavthecoder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

if (i<n) n=n(n+2)times

dlgenithm steps to Aolie any


puobe.
Preputis ot sgeth Time eomplexdy
*frequeney and sep cunt
1/P - Asymptotic notation
o/P
3 Precuon pinite no. of steps
Correetness
peform tuut ) Wost Case - Maxtume regiured
Average Caue -Average tume required
3) Bert Caue Mnimum tinn reqind
Detemination
Lo 20 o30 SO
Basë idea 23 4
best avg wost

inay seanch, S0 -- at last index the thus,


Bauie prpe 40 av
Peromnee beat
Method o dueistin
DAA ’
Flow o problem
Behaviow Analydiw Course
outcomes
Comyiexity
Pertormante 1Greedy
41 Dynamie
lgo-ppbcatin| oM
Analysu tstimatón of the
4fciy of dgeitum
Pre-reauisite krsuedge
bSpacscomplezity. DSA ,C o Ctt
tode
irt sat (int n) Constant tue
daymptotie Netatien
Yeturn n*n; Complexity mathemotuca! ealculatons do
Space = 4|
unt adt Cint art], int n)time =2 rompute dine complexities .
int sum =0,ij LËnear (() Big o lo)
time
2 for (i: 0gi<n jt+) complexity (un Theta
3)- sum = Sum + a I
4) etwn sum ; iv) ttle o (o)
(v) littte emega (w)

zempluritiu > Big o (0) - Ywmst eaue}

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

put valu ot T(n -) in eg"0


pul qreatst daweN band T) = T(n-2) +n-1 +n
put n as n-2
Tln-2) T(n-2 -1) +n-2
= 7 (n-3) +n -2
(n) T(n-3)+(n-2) + (n-1)+)
Qnt + n
Tn) = T(1-(n-l)+n- (n-2) +
&n'+ n z an (c=2) 1-(n-3) + -.... .n)
lt2+3 +4

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

T(n) = T(n/2 t C +n/4t 2¬ +


n/8 t3c)
teratiom Mastey Iheaem
30-01-24
Tn)= Tín-)41, T(o) 1 Method
put T(n) as Tn-D
T(n-) =Tn-1-1)+1 T(n) = aT n/b) +f^)
=T(n-2) + I
T(n) =( (n -2)+ 1)+) bi
= TOn-2)+2
fin):+ve funcim
put n as (n -2) o(n-e)
Case: f Tn)
T(n-2) = T(n-2-)+1 for constant &>0
Le, T(n) T(n-3)+ I+|+1
= T(n-3) +3
for constant [>0
T(n) = T(n-k) +k
put n-k 0
Tn)=(fn))
n=k
T(n) = Tlo) =T()
T(n)= (negagn)
(Time complexty - big oh )
Tn) = 4T(n/2)+n
Solve by iteration method
T(n) = T(n-1) +n,T(O)) b2
fCn)an
put (n-1)
Tin-)= T(n-j-1) + (n
n- T(n -2) +(h-)
put\ n e n-2
T(n) =T(n-2-1) n-2 (AB) 30-d1:24
T(n-2) = T(n-3)+(h-2)
put Tln-4) = Tln-)+(n-4)
in\T(n).
end)
.. T(n) t\n-2) +-)+n
= Tln -3) +h-)
Quiksort la, beg
put t(n-2)
In T(n
T(n)= Tn-4) +-2)+ (n-1)+n cal' partitton Aray(a,bsg end, pivotot)
yenerasd em beesms calauielk sort a, bog ivotle-1)
eall quicksst a, pistloc+1 ,end )
T(n) = T(n-k]+(n-(k-))+...(n-)+n
Assum n = 0

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

Olnlogn) ’ Time complexity (Do this step- ise)


(Conneeted
We can start treey
Miniu -(nst) any node
(Gredy achnioue Algorithm (T there self loops, then first remove them)
appusae tor best ssstane optimal and' then proceed.
soln,
Kruskal- Vertieus , )
should contain
Peims vertices of Graph G(V,E).
Vevertices
V-1= edges 3

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.

Sate 08-02- 24 Souree Dstination


2 3 4 5 6
Job J J2 Js
Deadlune 3 (l,2) 14
Profit 60. 20 20 (, 2, 3)
Job sequencing uit deadline (1,2,3,6) +
22

(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+£)

Tin emy9O(nlag n) fas chot


Date - 09-02-24 Algo. for Dijkstra's Flayd'lanshal
Dijkstra's (Graph, source) 1 2
create vextex sot
for eacn vetun in guaph 1 o
aist cvJ 00
H
8
add v to 1
oliot source] = o 3 4
wthile Q is not empty 2
s extrao min (Q) 4 o
for each neighbour of vof u
Relaxlu,v) No self laap °8
No conneetion 0
Tme complexty- o(Elogv)
Dijfuenee blu dind Mo Ho 1 2 4
and eengue and dood
gaty appneaek and 2
8
2
8
Vacant palhs +
-ve weight 2’3
8
, 2’4,32, 3’4,
4’2 43.
-6
10 FoY 2 ’3

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

You might also like