














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Here the pdf contains assignment of Algorithm design or Algorithm Programming for engineering, MCA,BCA students .
Typology: Assignments
1 / 22
This page cannot be seen from the preview
Don't miss anything!















( "g~U'M.~ s~U}@ Qh4! lhe e.)(O.C~ lt"Onttirta li~ 0 ~Ot..3 m~h ~l~c.oe,c
~,~e ov- b~ ~1<l-r~o.s~ "'lhe. '"f uf ab .. e b~ one.?
~~ ~
i) bou.'t>\l"'- ~ .\rtf ul. S' ~e. :. , '
2.. n L. , l , I • : :
t-\e.c...., \npu.\ ~i-ze z. O....n
1
t ... ,
1.. '
T(ln) 2- {gn) ::. 4 n?..
\
I•
t~ ll\ .. ,.e.n.,.ini .\.,.e. , inru.t , slA.e. ~~ I 'i ., '.
,.
l I \ I
""lVce. 'runnin~ .\IYl\e ine.<e.o.ses ,~ "ff"'°"imolelq .tn+ I · s~lfS'.
b) Y\
i) bou.,\t"~ ~e. t.,rut si:te. ~ ·,
-rl ") 2: n~. .,_
: } , I I j ) :
~e.~ · '.nf u~ ~,~e. ~- ~~ ,,
. I ..
T{_ln) :2 •• ~n) ,. iY\a ·
''- 'Y'Un.n,n& t1"t.e bec.ome,s
""f(n) L Y\i
'j
l • } I
,i , -:~mes
l ; f , I
\ f , l
. '
•: l
I''
I I.
. '. -! ·'
) I
. ·,
.'. :
c) l~an.
1
·.
3
¼t. '"'f u.~ s-ze '-
""t(. Y) 2. l O (.) 't_ ,.
~~c..:, '(\rU~ !\:;{~ '. .2.~
T(.2.n) 2. \C)c(42..n')~ ~ 'toonl)
1he. 'fU'f'l'\Y~
S\AE!. b~ 1!
'T(n) 2 ~o _'(_ t..
~ ~ , npu.l g,, ~e. ~ ~ t \
\ 2. n + 0
C.
tu" n ic) -1:l me. t" ~, •o.aes ,~ "f P •o~l mn l'< lj .t O <'», +I (') 0 skps.
d> n \c, ~ n
l) boub,n~ 4-te. ~u.\
T(_n) 2- n\o~n
~e..W (\f'.1..\ ~~e. '. ~r.
she. ".
T(?_n) z can
0 ~ (_2.t)
.- l n llo~'t'\ t lo~~ ~
: ~ .,..unin.ln~ .-,1"ne. \1\c..re.o.ses
r\u~ _0.1_ a.dd.,i~ona.
.2Y\
b~ o_yp-ro~,ma.-~~ a. k~.o-r ~ !
,y \n~-r~Q..S'(\i .-h~ '"'ru.- ~,~e _'°<:._ \ '.
'f(n) z. n.kgn
Ke.w inpu~ S\A.f'.. •. n ~ \
,(Y+t) i. (nt0 \o~ (_n+t)
loj (n+ 9 skps.
~c.'r~ a.Se ;n n ,
n
'!:. / \i
n ~ ~~ ~•G ')(\C~
fc-r n
~ I \
~ · ~'l>·•G'XlO
. __
:z G 'X \
. ----~----~---:---------
2>. lll...e. -1..e. ~l\owin~ Ii,~ ..- funaiions. "'-ncl. Clru,o~'-. ~"' ln..
,O..~<!.et'\d.1f.a 01'C1vt 0~ iTow""'- 'fO..¼. 11-to..- is ' .~ luntl.Han ~ln)
'fV't'Y\e.d..to.~l~ ~a\owQ lun~Han ttn) ,n ~awt u~+' +.i!.n i- Should
,._ ~e. <to..~e ""'°-\ f ln) ',\ 0(3tn,),
. ·...• l ~..
tl-\ \O <. \oo n \ n.. ·s < n l{)~n. <~ \ \C!>n.
V/n) ( f/n) <fJn) <-t(n) ( ~ln) ( ~/n).
~ • :1"~..t. ,-\lnt ~\owi~C\ ,~\ oi fu.nc..ian~ 1 ewto.~'- ~l-t~m 1 tt
a,.Q~~nd, "f_ oY-de)t a~<}'°~ ·roJe., ·Tua\ ,s i¥ {u.nt!.~ian ':/n)
,e_ --\.~ CQQ.e, ihoJ f t1 ,s. 0 l~ ln)). '
1..
2 .J 109" < "~•~ n)'I <~Ii (
~ <"1•'3" -( 2.~ ( !1."
i \ tn) ( i~ (n) { ~'t (n) ( i!l (n) (~
5
( t) { i~ (n) { i~ (n)
;. As~om.~ ~u.. \to.."~ {llnc.\lons ~ o.nd. , ~ s~h 41-t~~. f(n) t's
G(8 tn)) • Vor e.~'n ol ~~ {o\atAHni s\c.\em.e.n\s , citc.1t\e ~e."'ut
o.) \ai~ l (n) t~ 0 (tai, i ln)) ,
f (n) i ~- it1\J
1
01
, • r,..,. \oi
2
2
l\nu.]
' .. ,.. ....w l _ _ \
I •
hle.. ~n.. +<, show -tho} ~" .Jl. (-1') ,...,\toh wou\cl lmrl~ 41-to}
-\1..t.n. «~ts\s o. ®ns\o.n- c./
on.! n,, such .\1-u>.~ f M' a.II
aL n) ~ C. f ( 1')
H_n) ~ c_. ::\ (_,,) fo, all n>, 11
0
\n~llO.ll~ :
_ _ Qlr-
,,_+ ·f0)
~o.n
'
,y-e_o.,t1lG.n~ e
le.. ~ z. z
1
~'% ~(f) I ~t-h
a.nd
' r
~, ~ tla.
Q.o
I
c,,e l!on~\u.d.e .\.i.oJ i¥ f; 0 (i),. -lh.e n.. qz. J1:{. f).
I • &nal dt.T -\,.~ d.i-re.c.ed ··•a..~
f I!-..; f Os g i I, le .\o fol o(f c,_o.
o.,,Ju-n~ & '.
,) A, 8, c , t>
1
f I
E
J ~
'
g) A
I
c , F 1
~
-'no.\ · ho.ve. o.\Te.o..¾ be.e.n
o i e.o..c. h ino cl~
1
.s f oot.~n~
1
n.
--.\t. bfS -,-o..'le.TS.O.\
, Us~ o.. ~.o.c.\c. .-o. s.\o..-e. .'he_ t~¥n
b'f~ -\o 'r!Co'i\a.rUJl
.-.~ c..~<t\e
oi -\he. nade.s "lsJ\e.c! d.UhlnQ
ont
1 • ,
.
. ' 'I
,v b¥~. T~'1e,'1'S~l ~
~o~pone.n.s ~e. a.\so
.h~C?.\t.e.d ,'"'"'-o..\
_ ~'L~. o.nd. ls _ ¥.0~ : :~~ ro.ne.n- Gt. -\,~ · c..W1ne..n
n~c\e.) --~e.'. ~
Q~~le. u~ cl4rtt.~\e.d, · - _·
, I' • ..
a.ijc,\e. 1. d.e.-lt~~c: , u.9a 4.,.e. r=~n- inl'o,:m.;.on lo ·ho..c<,
'c>a.Qk 4ht. ~e1lt. ro.-th ~ncl ou~rui , ~.
I
t~ Rt_-\unn ~~ Dl' ~ ~~
..
·
C>ornr~\u
I ott\w,n
It No c~c.le. fcu.'t\d ".
f. ..
'
9' ~~o.\e _o._n.
i~~-
~ *ire.r r~s en*
-\he.··
~{°f'n
tf a ~
o..me.
Ju.~e..meJ~- s •
QY.
a.-rQ
-\o k~e.r
~t'O..Q.~
-~
"'-ac..e..
col""' O •
,,.) l't-· ¼e. ""'l<\h.ou>\ i.. uno.o\o,nd 1 o.olo• \. wHh -\1,.e "f P~.l~e.
C!.O (),- •
"} lt +ht. Y\t.\ l!,,_ .ou><.- o.\tt a.¾ .cu · .\he, so."'"' ca\ a..- '" -+he o.unnen.
1
. de.~~~\ec,
~ I~· c,.\o•in.'a, i". :"°'"'~... ~._\i q d.Wene.n-" f<>l~
-"'-va .~\oni - .-e> cl, ff e.ne.t\ <1.0\ars, ,
°"'► _1-'f ~"i • d~.tfene.~- ~ f'";,. hos ~~~ go.fYl~ (!O\oT
1
"-.en {h.e
" ~
1
9 l'- 'M ru>n~lio.\• 0>1.e. t .. un.d, -1\te. Jwl&e.me.n:s ol'le. ~nsls\eot
0
;,. o. .-oc,~cl .\ne i,.: ..&11,, f_....1, ned; l..a.• al
. ,,no,.\ "=. o.h\d.,o.n,
bl«"'Q
1
-.~a , ~h·,\cl~n. ie. exo..C!\~ · on~
~sis -"'-~n ---.e -n.um~t.>1. ot \eA'lle.a.
,
~'"e .. CQ..s~ : I
..:►. ,
1"Y
Cll. C!::l'l i c.btu\ i:. 0
! Lt.Q."e.s - \
\nc.\u.c-"e s\e.p ,
i) ~nsl,,
-II,,,.. '"\lsftu ~
~
1
----t---------- -------·-- ·----------------
<x:i~-_
I
.fo-rm
'
·h·e.e
'1 t
t) ~<le\
o.. ne.w nocle
~ T
~
0..
~t.w evith
n~\
"<\od~Q .. ""Tht.)'\e. (UU.
.\u,o ~se.s
'"-'e.
ne.~ noc\e..
o.s a.. , c.h\c\
~ 0.. le.o..~
node 4,
Q.a..~ e. \ : Ao.A
J
'<>e.~a.u.s~
tn.o~ hQ.~ on~ ~-ttld 11nd. d.oe.s n.c\ · bt.<~e>me
o... n ad.~ t.ui \¼. .\u..,o a. h•• \cht e. '\ ,
I , loe c.oJ.1.Qe 4,.«
a.M~ 'tod.e. ts a. ,1.e(,d \e.o.f.
()l 12. <'J..... O:il.d
f\dc
..\.\e. ne.w
~
1
z ~ +l
z> ~ z ~-\ _0- \
, l.
,
'X.:: ,x. t \ a.nct i z. ~- \
u~,t~ ln~u<!+Jvt f~t\te. I ' '
'
t2 s (~e_ ~ \t)
R~~h~ c.~itc\ ( \ tl:io 2 -t 2. z i) ~ i •
e.U})'_~'I'\ - ~ ! \ (.
~ i
,.
' ....
t I • • t
. '
l I •,
W,-,.e. a. p1e.lld.6e!ode for 4kt fro~~e.s :li'AP--M~-
i~TR.t\C.i\ON- M\ N, ,-HzAf-b~'1R.tA~t- "'-E-Y ~ ~\N ... tti/\f>-\N5tl.T
-\hol t~f\t.'t'f\utl 0. 'M\Y- r~:o,.,~ ~~~ CPi¼h. Cl. M\t\ - heo.p.
I
l".INlM..llM.
~n~~ i
1
i
;) ;
·1 HEAP .. E'X TR A<! r\ON - Ml t
' ,,
Ye..\otn tt ht.Of und.ettf\aw ;
mtt\
st'2e :z
(A,
tre..unn
.~Ar- t>EC.icf\SE- ~E'(
\ iA 1>- b E<:R.flAS E-
I
*'k\w,_Y* ~
~I.a.YI. OU,O,e'I~ ._~••• j
w,\e.
J)
' iWO-f
1
t,) ;
. '. .
/
M\N-
l~, ~~)
--\
... }""~ 'W_~ I_C,
.. A
'
. i
r ~~ f,a.,~
.[rt) , ha"'""~ .,fn ,b ,o (r~ ri_) ()_)
. 9u<!. ~ 4-hoJ
.- ' \i,n i a. [n
'
• .. I ' ·•
,/ 0.hGCS~
'VCl\u.u ~or n);.,G, ,ld~ h~"''- \iY\ '.fl. ,. ' ' ' f fun~\ton (_ it\l
-!
l ,. (n 2 2. ,) --· -
,-t.b1\ ; .. e..\se
....• • • 1 •
4, ,
fun~.ton (!'(I)
fn· l;1 l ; i {::n ,' '"'
ttme Clamf~~, ~ : \ Ttn) z. s,("ls)-\n.~,
1 o.(n) · ~rrli'ni ~t. M.0.1\tn Th.e.attfl\ j
. ,.
,. : · :• ..... :. o..: ~ ' i(n) .1. o(n) , :i. 3
\o~bo..
n. ~ n a
T(n) z. 6(t\ti") .
..
.
-. i
' . : ,
1- t------------ ----
~to)
'1"'P E ';
Re.f tt.a.-
l:e..T'f\ f ~ 1-e. hi r +'
"12 n;, ;
UnU l n <:: l
J '
\,.~ ~:...... o.nd sro.e.e .,_.,;,rk~i¼J
ihe. t,u,c,_;
0
1\ u.,._,. a. o_ena\nn- o.ma~n\ ..- 9p"-'"•. for {he. V.UU .. blu
.\e."'f , : <lnd n. "Then.. 1s M ""-=s111e a.a.II i>• · o.dd'Mono.
mertU>•~
a.\o Q.o.Jion dtfQ.-nden\ 01'\ n , r • , • ·
. ". Sf o.~e &rnf\e.,o~~ s O (_,) ;
9o\ve -~ fa\a...tna ,-e.c,UJU1.c,_ncte
'M.e.--~c:U. If no g~\l1{.n 1s roui\o\e, jus~\V1, uslni f"'°ren
ere. o..santna.
'
s.,
1
i'
+ !lT(~) t Q(n'
,~
n;>Lt
I
[
I
t
:t c.n
'9 T(n) ~'Ii(%) -- <!.Y"-
o.. 2 ~
'L
tln)2 ~"-
\
1....
ff. a~b q_
f(n) 2 Qn_2_ / T\Oji,~
T(T) 2
9
b1o~~
/
e.) ,tn) 2 9T (
0
/41) + n tt\i rn..
a.~ 2> ; b
nl(!)i n
lo~ "o.. 2 loi I.?> .2. o • ".l<\
'Y.\a~b°' L n()•~
f-("t~J , ~ t•a (n/'1) 2 ~ (to~n - lo'.l ~} z "'
1
~a"' - \
"
~~(~) ;l. ~c~\o~Y\
cfln)
~\o~Y\ .... -
'-\
C!. %~
,l n) 2. S
t> "f{YI) ,. 31"( "Is) \V_ ·
Q .. Q,
\p, 2,
~o~bo. "= ""
~; t
'(n). o l~-~) .It o(_ n.'A)
,t~), a 2 ¼
12,tl~) ~ s. ~t ... :. 4n{
«~ ~ C. .Jn
~ ), ../3'.