DAA Solution

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Aa)

int fun (n)i

times
for lj: 2; j<n; j-je2) ’ loyn times

27*n =
Ofrlgn)
(b)

T(n) +

- T(n") +lgn' g
T(n)

-T(n)+
=T(2) +
yn. ..tgngn
7,t..-+
I+
Cosfast
(c)
T(n) n22 2+
423 +....
T(n) 2 + (3) +. .
We
AGp
n T(n)= 2. M
T(n) = 2n
Th) = (n)
(14) (()
(30) g4)

(6)

(55) (9 42) 30)

Finl Heab 99,75, 84, 55, 42, 24,61, 3", 8, 1

2(a
B-1re with mi ni mum =t
# Chid Pointn

2.

1 2. 2.t 2. (t -L)
2. 2t 2t2 2t(t-L)

2t
2+4 2+^(t-L)

|+ 2lt-1) + 2t(t-L) +....+ 2t^(t-4) <n

I+ 2(t-1)+ t +
t- 1 (n-1)l2 lt-1)
t- 1

-1 < (n-1)
2

(n1)
M

E H PTX

delete H
M1
|M
E I
PT X

|SD| FG| KL NO

delebe &

MI
E I

K L
NO PS VW

|delete I

EM T X

sD]E GKL]N OPS Vw


(b) MËnimwm blade
| t 2+ 2-+...+ 2
2
2.

2.
Right
Retdtion
5

R Racolong B
3
R

Righ
Roton

2 (c)
Maee - Henp Binomial Heep fibonacei Heap Trie
O(1) O(L)
Insut
Minimum O(1) O (n)
O(1)
Extrac t -Min
Uion O(yn)
O(2)
Decreae kt o1)
Delete
Olyn) Olu)
3.a)
Sucbig
UI C K S O RT

I C k

IC k )
R

Pt) T U ()
as(o, 8)
4 =p (o, o) as(õ,3) as(5, 8)
3 = P(o, 3) as(o,2) as (4,3) P(5,9)= 6 Qs(5,5)
1= Plo,) aste,o sa) as(,8)
X P(7,8) 9 ash) Äs(9,9)
Time Compiity

Cost of MST = 3+ 4 +G + 8 + + 2(n -1)


- 1+ 2||+2+ 3+--_+ (h -)
- 1+ h (n-). 2
2.

(c)

20 A
--lo

if
LCS (m, m) = MAX JLes(mtn) if xCm] # YCn]
(Les(m,n-)
|+ LCs (m-,n) f xCm] = Yn]

m= 0 or h=o
MAx LCs Cm-1J Lu7
Les [m] [n-]
|+.LCs Cm-L]Cn-] F x[m] = YCn7

Time Cmplui'y withoutDP. = O(2mn)


Time Conpliy wit DP
X= aba Y = baab
LCs (3, 4) = 2

LCs (2,4) Lcs(3,3)

I+LCs (i,3) |+ Lcs (2,2)

I+Lcs(o, 2) LcZ(i, 2) LCs(2,1)


I+L<s(o, 1) I+ LCsCI,)
Y
o b
2

1 1

X b 2 1 1‘

a 3 2 2 R 2.1

a, b

() A D
Jo x5 5x20 2oxlo loxs 5*40
M
5

3SsD 2 2

ISoo 22 So 3
3
12so
2
2ovD
S

Mltipleato =
Ordr ((ax(e*c)xo))*)
Items
I
Weigatlw) Paf-(P) Plw Ratie
I 1

I, '5 o.7L
I, 3 o. 33

W= lG
W =|G
P=o

Upto = 1749

W= W=|6
P lo P=o
Upto = 17 Upto = l6

W W=4
P= lo
Upto= l6
Anwer

Masimun Profit = |6 (I Ta)


5. (a)
Patn 314g
Pattew 2. 3 59 o 23 | 4 | 2 673 9 g 2. I 3 9

Valid Mateh Spwnisuy Match


5
(b) Bo

5o 2s 1S
20 |2.

w(,s) if R=4
TSP(, A) =
MIN 3TSP (k, R-k) + w(o,k)}

TCn)= S2(2")
T(4, ie,c, o}) = 43
5
12

T(8,16, b}) TíC,te, D3) T(0, L8,c))


2.S/

T(G,iD}) T(B,1<3) T(8,2 o}) T(D, i 8}) T(8, ic3) T(G i8})
25

TlC,) T D, #) T(G,) TCC,) TB, +)


TlG) 3o
20 2.0 3o

(c)

NPH NPH
NP If TsP Prbdem
P Solued in P-tine P= NP= NPG

N PC

You might also like