DSA 2 Assignment 1
DSA 2 Assignment 1
DSHADMAN to:
MD, bubmitted
2217 C3E Code: Course
249 222 O11
T5LAM RATSUL MD. Name
Assigment-1
ALGORTHMS
TT AND
51RUCTURE DATA
Assignment-1
A[n-)..(n1,A[(n-)..n]
4 |:
S0, the time conplexity is,
T) o(nog)
we krouw, in the conplexity chart otnlogn) <0m
Hen ce, i ide-and conguer takes less time
to solve the prroblem morte effieienty.
Ans. to the Gues. No-2
posz1 2 3 4 5 #
A=-2 3-2 4121
MSA( A, 1,)
3 (6.)
s24)
MSA(A,14) MSA(A, 5,,
5(a.4) 4(4,4) 2 (66) 3(6.3)
r1SAlA,1,2) MSA(A.3,4) MSA(A5.6)
-4(5.5)
2ta4)\a(49) (6)
MSAA,1) MSA0A2 2)
) MAlN3a
MSAlA23) MSA(A,4,4) MSA(As3)
MSAa55) mSA(A,6 )
Explaimation:
Artay oige ¥.
cum 4 Crossimg sum
Left: (1,9)
s(2.
(4 (3.4) 5(2.4
4(414)
(i,)
s(2.2) -(3:2) 4(4,4
Right:
(5.)
a(b.) 4(*)
-(s.) () ’
-4(5.) 2(6)
(s:3) (b/5)
L=1 5 9 1015|
2 4
11 13
1 2
10 11
1 8 9 14 15
2 3
4) (L,R))
1 46]6
45
4
) Le1, R[31)
4 5 9
) (ea *a)
789
) ((1, RB)
4
L(6], [
13
i) L($], RSI
13
Ae tieity: a ay
850 1700 300 300soo1206
Arrival : 1000 340
2O 00 835
104o 2000 1800 IG50 1380
Departu re: 1030 1o 30 1040
[1000, d036)
3. ag ’ [1200, 1386]
4. 1500, J650|
a4 ’ [1700, 2000]
tollo wing the conition
By gnead nethod, the
5 trams CanN come to
that
platform ithout ouissio.
Can e the
10tat Maximum 5 train^
platform.
Ans. to tho Ques. No-5
n 45
eb 141
2111 1 54
3 57 t 6,9
129(5,)
99(u)
71;0 57,S 49:t
45
843 a
J26
155(0.a)
1
49:t
99
45:0
49 1
281 210
155 126 99
54: L 45n
84:a 49% 141;2
57S
Code sord:
t
001
oo|ooot|Oto1|
in
btolen 10 de o
For tixed length code 9e need 3 bits, A5
ther ane 7 aharracterrs. So. for y91 characters
we'll ne ed (yol * 2) 14 34 bi ts.
491*3)
forr huffmad eneodig ’
3* (fre. ot a+l+n+0+s+ t 2* tre. e
A.
oims,. 4too and coin one
ken Coims
to
15t44 =
totaa
m bo,
2 2$ 2. 2
3 2 2 4
2
2¬ |<2
243 2 2
4 434 3 3
2 2 2 1 1
34 3
55 4
445 3 2
6 5
8 2
3|Y
15 12 9
3 2
10 9 8
12
15 14 13
1
L+2 1+22 |+22 ord 3
or 3 or 3
|+0
1+2 42 |(42 1+1 An 9
1+3 t3 (+2 or3or3or3 Z 20
4or or 4 on 3
H2+23)1+2
(+32 orr3 2or
orYo4or5
14 6or or 5 or 1HeQ1+He2|
44
43Y4 43l+2 42-3
orr4or 6
or 2
or 10 or l9
12or
e 10
12. 4 3 2
12 11 9
15 14 3 method Tabular
15 Me Hete
)
No-6 ues. the tDAns.
Ans.to the ues. No - 7
Lets ta ke ’
5
Length, l:4 4
15 2
value;v 2 11|
Ta ke -O
wciglt/3 2 3
Value I80 170 120
Here, Capactty
Using the bottom up opprco ach ’
ite 1 4 5
2 180I30 330 B0
|70 180
350 350 350
4
5 210 380 00 390
fractional Rropsa ck:
items = 5
capadty
item 2 4y. 5
85 40 T0
Proit(par 9)
item 0 prcofit Remaining
210
420
´picofi t 500
Ans to the ueb. No-10
CATALAN():
rreturn 1
return memo ]
foreie0 to n1
C= e+ eATA LAN C) * CATALÒN (-t-1)]
meno[n] ee
Teturn e
Recusssive Tree
CATALAN (3)
cATALAN )
Value
1 1
2 2
Ano. to the Quos. No-41