0 évaluation0% ont trouvé ce document utile (0 vote) 22 vues19 pagesDsa
Copyright
© © All Rights Reserved
Formats disponibles
Téléchargez aux formats PDF ou lisez en ligne sur Scribd
i tliat
I (Qe
_ Gepla! in_Jomo game _poob tere 4 —
4h hoe Jump gome able is. dleesic- alin
= —_|__Problem ee 2 sett .
ee —PaTERNL = = 99
ie By 58 ae an_algorithm 2 +0. ‘dade ‘atenel sing — sigh linked _
| _=2l_ Hee the “algosithum, caxislen_in_pgeudo@de — -
| Function _delebetaom linked List (head eee)
— Z_check- Hh the_linked_tisteis empty. ss
| if head is nalli
| | deen nul)
| carmentnode = bed
Pagvious: = nul
| eshile_copzeminede = isnot null und codventNode + value _s_naf
|| eQua) +0 \olueToDeled
PreviousNode = (oapentNode
I Seley head
if__pmeviousnode is nus
[| hen = + Ne; =
I ese *
[Prout 2 am
ot Teturn head
i
@__ Gxplain the concept of Stock:
Lp is last —Tn- Fest oud CLifo) ~ohfch mone unas akeyo chase |
_ lost element odded +o the stack Is she
__gemoved .__ vi
Aement +o be
The Stock has 4200 prim sy opedations _» push and pop:
___—The_push operation odds on _
_-Stock »_eshile_the_pop_
_ ftom the stocks
— The Stock_is_commenly used _in_ computer science, fogeamm-
_Ing_and_other-_sields_whme dado needs 0 be sioved
_——and —accessed_in.o _spedHe oadey. ey
2 Fach, -Hme_o_new functien is_called ids ogguments and_tocal- —
———Nomobles_cae added to the top of the stock. ldhen the Sunchon
_——~2eumns__i+5 Vomable cae removed fom the stock-
element to the top of the
operation temave. the top element
_&) Sxplain_need_of pooaty 4 1 a eee
—Z=A_primity queue is o “dado shruckme that ove allows she
= frimity queues_oze_oseful in o_vomity of application whee
=__fer_exomple — 4
—— 0 paradiing—system i= _Inan_operabing sysiem_s processes_may
—— =A paiomity queue con be_used oe manage the oxder in eshich _~
Processes cme scheduled . .
——=A_pmimty queue con be used +o construct the Huffman tee
———whith_Is_used_40 delermine the showtest code for each
-symbo] in tne datta,
= Wall, the need of primity queue the items peed to be
he ttmty_moybe_based_on any numberof feckors Suh
~~ S_togancy_. impmadonce: 0% weight: ; 4
= eof prionty. queue con help Jo eptin/ze—pancessing__~
~~ Himes _and_ensine thoct high prnizaity —Hbems-o0e—fraocess ed —_-
| Figst- Aoes © _@mpoxe OFS and _D#5!_—
= Breadth - fixst Seach | —
_|B45, Breadth ~ fizst+ Seorth._'s.0- eo based _ Eran fo
nding the Shovlest poth in the gimp at
Fuses o Queue dato stauctse_that follows fits+ in Hest
-ovt- Tn Bis one vertex is_seleded odo time when itis
Nisited and meaked +hen_its adjacent ove visited ond_ stared _
inthe queue. —_
Th is _s lowe than _Dfs-
—Exom plet=—___ - — -
| _Thputt = pe Oud put — A,B,C DF f
HL rs a Se
S
pie
j{_Depth fias+ search: —
| bts Depth _fiast Senvch » is on edge — based Jechnjque- Bases
[ne stock dada Shuck _ond_performs wo stages. fins
— | Nisited vegtices ode pushed into the stock. ond_secand if
- ee _che no _vewities then visited vertices ese popped.
L —| Example! —
Topi A. ouhpud! =
& ok ‘[Link]. fof
©__Poply the algaaithn to drow Dinorsy Seach Trea fay fallen
L t data — 10,12, 319,25, 28, 30 15, 56 4
=I -
9 —@
be _ “Bap0) Explain Max Heap! — |
| In 0 mox- hap. the poxent ot got node i's usually
| geateés than the childyen nodes» The momimum. element can
be accessed in constont time since it sad index 4+
@. aimee se
@p—
ape es
Tnplementasion — PAS ede canal ai dil ot
i Similboly when illus tio ding_o_max-heap-we- use adtwee- >
| based _structie but when vepresenting in _memosy we use —
| weoy- based shucivse - Consider the figure below shoeniing the.
| daee- based ond memory. - based_sepsesentation.. :2020 falesn PSA
| eee x-men —_Plgcarthrn. —bineay. PA =e
10 6087 JS %r1B 101s 09 | 17,90) 18104 7 OST
opting ti. 8S _
_o Explain Min. Heap | ——
Co es »4ype of heapSi= Min- heap ary play: Heap
GPL 5 min-henp ig used: to” acess the minis um_element in the
heap -
=A Mox- heap ig used +o when oceesSing_the roxcissum_eleme
in the heap =
oe L ~
Tio] 25 Be] 32] 98/5/55In o_min- heap. the first element tni's_null_ond then the
Allowing _fsmala_we orpanging the edement:
— Pirent_node tt
© _Eqain Bier set
go) ___the power set af 0 set 5, dencted _98 £(8)..-13 the set of.
oll posible subse#s_of, _indluding_ the —emply..S eb.
_——>—fas_exomple_,_consider_a_set Ss {11%}. the _pawey set of S»———
_-deneied_as p(s) 5 the_set of oll_passible subset ofs _
Pes) = 2 §§. 033.223. (ee} fp. og NG
Th e_set_S= £4,2} ove included im PCS) 95.
___mell_os te subsets £43 ond (24, and the subset £423 which.
______indluded_otl the elements of S~ aes
ra Rowen set (5) of o sets is the Setof oll subsets _<«
Jo example _— a
sto se [Link]. then p(s) C03. Cah.fb3 [ep
Loch, Cb}. Lorb-c3}
ga)
5) Define Hash function 2 Collision | —
7 __B hash Foncton 1s _o methemadical function that takes _
L input dato shring fle o&_possword_) ond veturnsofixed
——ualse_size_outpat uaJue. 1 Knomnoso hash_oy_message diggs
= Hosh_funetions ome _commonly—tused_in_eay ptogsaphyond—dada__
ES ee le
Fe j
=f collision _ocuas_in.a_hash-Soncion_ahen two different inp
Values produce the some output hash Values
| —4n_othet words, two inputs have collied 4o produce
es Same output7 Hash Junction 2. collision. tefers..to_thesevent whewe troy
_.. diferent _inpuds . Paoduce. the.same_hash.value_ forg
.hosh_funchfon - se
Therefore hash -funcHons with lows collision ates age
_Poeteaed Joo Seanity-caitical. application a
—Specitic
© Constouct Bincoy tee for. Folloewing-deds,J01251 214.1013, 4
(ux) 22. ond__delesmine_inowder. postoaden 6 _poeord ed
2 Jo__constouce © _bincey teee. [Link] by-sulecting!adoo4.
{node _and.then adding “nodes to. the let .ond-mght of the
+-Bo0t as necessary -_ L aecicitheen tne Ae) ee
T We toliow o specifi -ordes_while” odding the-nodes +o maindair
~—the_binoay reels poopeodies mena Sie yeti
F Here _is_the_binady hee -of the giver: datas ins ban
of Ba at {ms i
LON
2 2
a ae
/ 0.
_ yy 8
—__.[the_inoml 2a_drmverSal ofa. binay see Visits the left su bloc
ial —Hiel._then_nede_goot_hode_;onj then igh sublave. i
=the inaxde_binosy tree — (LPR) uu!
Se as ee, Soe De td 2
— The. [Link] - ct. o_binury tree Visitsthe lefr
subtree _fixs),_then_ the ight Sublree... ond_¢hen. the aoot_
node. = s CLED)
‘The__postowder _binerry tree = | aay
Hi U1 2 28r RE Nab oa God 2-92.489 9-28 10 _
The_preoxder _doovursl_ofa_binusy tree visits the woot
node, then she let subteee tand_then_the myhs Subseec
the _paesmder_bineny tye — (ER) —) (pik)
fo. 2 4nasy (3 VL Bees 1 ee
dyateay ; :
What 5 HomiHonion_ ye? — :
7 A Hamiltonion cycle also_knocon_as, homiBonian. einen.
ir 190 cycle in.a_ Goph_thed visits every Veatox exactly.
once _and eracty etuyn 40 ids Sloting Vestax « =
+ In other coords. Dis _poth that passes straough each
i _Neviox of _0_ggaph -exoctly_once_ond_end_of Staoting veataw..
dowming— 0_closed_loop + ore toy = _—_4
7 P_groph_sthe_ centaing Hamiltonian cyde. “colled_o5 a.
Mamiltonion gyaph. Bie —
i$ Hamiltonian aces _ ove. named_attex_] Llillion. Rowon Hamilton.
On Smish_moshemadsician who sensi. tapeaiact = tontaibutong to.
| -gzoph theory in the ig-+h cent a ~ |
5 —Thes —hove_mony_: applications sid mnipuden aciente physics —
(end other folds sit 5 Se an
They_con_be_used_4o_solve. _op}imizadion_peoblems. 40 ____
= fe ee pooblems..-@me
im
"% date _on_< agen. 49 int rambe—of nodes—in-sigy—
| _linked__lis++- —= 4
Inijidlize a variable" coun} to 0 1
_ Tf the head_of the — linked lis nal» srebupe Pa
sthanmise Set a pointer | custeni! 40 the head of the __-
Vinked lis >
= while! _ceeend is_notnull ingemen\ "ound! .by Gienjuul|
move! (uyzent | 30 the next _nod@ in the linked list ——___
__ pelugn count’.
Heve!_the—a)gonith nets ————
_ function__countNedes (head)? —_—
counts Oe)! 8 ies oe
vc th heed. sot il ie sade:
Tehign CountLeobile comes LS nulls
coun} = coun} 4 |
Ceagen) = coment» nex+
Belen (ou nt
this algorithm will -taveasethe_linked lie once_and_
coun} _eoth node + =
whee n_is the _numbea of nodes. in the 2 linked ish
tun)
Whed is dump_gome algooithms Ee a ae
Jomp gore is_an_algon+hmic_paoblem shat _invelves_ desea
ning—whether it is_pessible Jo _@each_+he_end_of ‘an _ —Otray
Foor jumping ee one 400m: onotheas
aan The_Jump—gome_algomthm ton be_salved_using. simple.
—!}e0ative_appacach that involves —keeping_index that con be
—_-veathed 400m __cneentindew.
=_fH_each_slep_tre_algomthm checks if the arent indo
. less_than_o% equa) to +he seaehed armzent Mmdoc
——— Fothest_inder.
=} id the_is_thon_the_algonithm updates. the Soothes —_
a eased thei _Jomp_lengsy feom_jhe___
|
tT cement inde».
= It the _fasthest index _is_goadey_thon_ov equal_to tne
eaten te ea
de§__nJump¢ bums)
N= _\en(_nams) es
“tee ses,
Fom_1_in_gongetn).!
——_| if i> Jepnesht
a : BeArtryp—Fase- 5
=a eal Forjnest_=_moax(dosthess, 1+ mums Ci.)
i Ib Somthest Dan- 1:—2elegn True
$094 4the following “deca _usi!
i 2g tatty tnt
(=? Hoe ome the sjeps_jo_stad_ste
set_alganthm —
oO Divides _+h@ ist indo te halves 1”
(98.29, 1 43\, bh gg, 103
Cas¢ 2% 49, $1 (9, 8% 10]
ss pal -Divide_eoch _sublis+ imo Jw holves ageing
£38,291 043 ,0) £9.32) Cel : 4
Lo G)-continie—divitgunlil_eoth_sublbtconlains only ne. st
ye [ -eJemen} — ‘
1 fess fen\fsel fo] to)tad bed
—?: Meng e_ste_sublisss bas ge ga
_ 29,989. 194 49) (4% pcx £ 4
| £3, 29148, 98) C9 101.99) ‘ s
| [81910 2119 43,38, 82]
I. So the sored lis: i i oat algom thm 1'5__.
i (9.9110 727) 38) 43192] j
{am
Explain need of -circalo queue! —
= Ai eivaory_queue_is o_dedo_stsuctuse_that Shmes—a_fixed =
———Size_collection_of _elemenss., eet teh
+ 31 hos sovenal advantages oen.. sth 4ype_ of queues,
—H eee eek inertia Speen
= [oye ok the_maleoduantag é = obs einer qsderé is: thas ds —
> ollews efficient _use_of_memaay.: 4
oF tntlke_o_aequlerqueueswhich has_a-fixed_size_andcan—
|p bene sath
> B clrculayr queue ean seuse the Space phat has been faced)
heel eee keen: ee TF_____.up_bytemouing _element— 400m the toont of the queue,
ss Thad_meansthe_Cacwloy queue ton. stove. move emeng
_______ tharn_o'segulea_elemenk_queue_of th Same size,
Pnothes advantage of chrulaa_queu®_is_its abiliS 4 Jy
_______ pevfosm_tonsiont_= time _opedadions on —both_end of queue,
= Ciantway_queueene—commonly._used_in—compus@ science
| _______ fow_vavious, applications... Such _0S_opewah'ng -Sysem.,
Sob_poocess ing —_sysdems- a
+= They—ase_also used —in_hersd wage applications» such as
we computes: memony 2 — St
(2) Explain pales foto .04o__of __Hopos_with on_su ial
- &xample —— =
= tHe _tomen of Honoijs_o classic meshemachiccd puzzle
———thad_jovolves_moving o.set_of disks fom’ one pole_jo_
——anethee_using_o_thied pole _as_o bulfeo.
}_=—The_objecive ef the puzzle _is46mmave_all the disks dom _
the_fins}_peg do the _thigd pegs asa
—_>_The_®ue@5 of +h Toweg of anos aye —— ‘ oat
(= @_-only_ane_tisk con be_moued. 04.0. time:
| —@ A leagea_disk_connot pe plaed-on-Jop of a_emallea disk.
| (9) ny the_opmest_ disk conte bereaved _faam.o-pey .
| A ee
v
|
Loe exomp\e is ——
} 0 Arial ton figuaneion —= :
- ut Towey 4.2 £91241 :
Toweg 2 30)
Jowes a. O)
@__Goa\_Ontigusaction —
sdf Towen 47 1 %
I Jowes 2:
I Jowes 3: & 20)
L
i
Lwe need_4o.- move. -the disks f9om Jowey 140 4tdcue9 3
Sor Say) Dales -
@_Hep—4-t-— move the smoiiest disk (dist 1) eae
Jowed_\4+0_dowey 3°
_ Jowes! 1 03+ 2)
Moeret ti in an
_Towes 3+ aL
O:shep-2 = move the middle. sized disk Cdisk 2 \ om
___Toweg_|_40__toweg 2. Sue ro es
— Jowey i: (31 oa
0 Gowen 2 TA) oat sos ot
i= owes 2’. (4)
~_ © slep 3..= move the _smallesd— disk (disk 4) Prion 28 tower
B40 Fowes 2+ nS ela ie —
jower 4°» £93 wo ion nedtnin A
a towes 2 + (2.1) oe es iz
a Jower 9. Co] : sarc ult Li
Algoorthrn £ a
LL Reamsive _procediae do the Towey—of-faned —____
—__probler. Jom an_disks + is iy
Towers (01 Figs); mid last) synthe E —i@
Slep 4." = Wf nzl_ then ___ - = oe
= woe. fxs} -2 last = oe
—l Delon, - : - 1
— end If
~__ Step 2° [move _n-!_disk foam cod “singh to. Ew mid} a
eee en (nel) inst mid logt)
| Shepas wore _Jinsd =? fash :
a shepu _Lrmove_ns_disks—fvom—vod—mid
Neo Wt dome _ Cn fins, mid_last) —
ep 5 Betams pe: |Con
_ JAhad_is—perspose of linked re
—> >the puspose of linked _list_is 4o— moovide_ on efficient ta,
_ 4o_Slose_and tehive_dedo_elements_in_o sequential _manneg._
_____ +A linked _list 16.0 dado _stouckre consisting of 0 sequence of _
nodes» - ee
wey Wheve each _node__condaing_o_dado._element_and_o aefegence __
fo tne next _node_in the seguence = Sa
—______>_linked_list _ean_be_used_i in_o_Wowiely_of- applications including
implementation dynamic _data_Shauchupe such a5 stacks, queues,
—_—.and__hosh_tobles -
They ove.also_sed_in_many-algomthms ond 1° poeggam=
| [ea pegs ferthets_aliy- dn ngznt cree seme
ap Samer of thet —__ ate ie
on_ effi re sty dacehtna andicnnon date oecene we
| |_dynomic_and_floxibl@_monner.
6 | Consid ex_the instanceof 0/1 linapsock _ponblem_n=3,m=%
qr) || Peles,o4, 15) We (18) IS¢ 10) Using dy namic paaggammi, oy
| Detenimine sme optimal firifit cind the Solution yecten.
$o-_selve +he—ot+—
aes | eee WWe_can_fill_in the table using: the oll Oudiing Se aiasive.—
1 | fomulo:—
|__| Jel TOG) be the maximuns profit. that can be.
—ebloined_using the fist {items and_o Krapsack of
| | capacity _j =
Ee nit: mox (rlirD.0). + Li-A Cj wed) ptil)
= if wo ee jo
Tig = rLi- MES) iE wlil>y
1
{|
{
seat Osing thi orsmalo_ we Con fill in the table os fallow
Hers oe We ee
6 Is 16 191868 G6 @ey 17 1819 20
4 ° 8 al 0 1 re a4
1 199 yon FS
a hy pene i
h 10. OLN NG 1 Vey p ap FM AS NG 49,
‘ 5 — J
SIGNI IG IG 5 5 yy ay 34
The ophimal. profit is. sy which can be. objained
using thems 1 and-2- Cath sol hts 18 and 15). ges pechyoly y
$d. Foded coeigh).of 33 a
(2. Wdaie_on algomish mJo..devsase. Jhe_nodesof Linked. Iisd —
= 3% Jnilieli2g dheeepoineas prev. cys and nect:
_ Set pen. Hone, cerya_to_the_head_of -he inked 1st, »
and neh do Mone. _ih
Tr SY noch JO dhe ened node of coma. cs i
7 Set the —_nexd__poinhem—of eae to. prev +
Sel prev. doce ene ie ———-
s7_ seh ftr_t0_next soe
Femetion L_aeverse modi) “Git ai is ay se
ms Noy prev senu)if {ok Sees |
Nay earentiz node)
Nore next: >_null>funcdon gordlisd Arode) tes ete
while (rode } = rou) £ ee
duument + umie (rede data +" ay
node = node. next)
34—_—_ ;
Gs) Vite on algorithm dejele element foam linked. ‘ak hse
Surn_is_equa) 4o_ 2670. _
7 gemeve Liement ( element) € —___________ =
—_=
Now usczens = this - head > _
Vow. gue = pat) _ 2s
ebile_Cummen: 7-2 nw) $721 ot 2
_C womend. Clem eae
EC poo s2 no)
this. head = Crexent. nex+ *
3 else t
BN nex} = comment. next.
iL this ~ Size =~}
telson coment dlemencbi
| es Poe = eames
‘aa =
ee BiB 0D BrPreD-J———
yefor®rpsy
a . To
| Find the. -longes+ Common Su Reequence_jox_foliowing —
sining, ‘sing —dynamic_ppogea mming .
pig toe etn sf
JM 2—COn—USE_$he2_mactaix go ssave_th® —
g#p_of_the_Common— subsequence _behoadn. th e_two sinings
lep=by-Slep mores. do find the ——
longest (©mmon subseiuence.Sep 4- Credle 0 madlax of dimensions (mvt) *Cnd)
and iniliviae the firs) gow and Shor Clamn Joo
Ile lploty
oO 8-29.
}
haa
1
lf
1 |
AE
hd
Shep 2— Fi in gne_madoix by Heading though. och _ducaches
of 4wo Stings» ~
+ Soy each choyader of » ond Y sf the aosas match
jee add 4 40 the value in_the_el|ond eH of the comment —
cell 3
“"e vess
rsels
22° °%G00G 0g
()c}| easy) Ea
lololdololol 4
Alojojoji|41] |
Ba 4
cJols|t jt] 4 7
ae ae -
Bloldja)2) 2)
Blol4| 2) 2) 2] :
clojefej2)2 fo. ae A
PJ alel\ej2)2 |
fF fole2}2)4] -
~Step 3 = _dpeel orfoace back jroaigh. he. madoix 0 find she
tong@+ common subsequence + i ot
me COMMON) SUNBEQUCN CE1G) BL be
lol ofe}o joy.
plojoloj4l 4
_ el ineSK
| 0-3 tony ae. a
| following doda +
Troversals
pam. Jo bineay Seerach ea. hee _fery-
ere Inoxdeg frevsdex and postordez-
B4, BUS. 56
3 To drow _o binoay Semmch_ hee 1 we stat b
oot nade, _cohich ows finsy value
14 4o_4the Corssent.
Jena Mgnt.
Caeaent_node-
199.991 61,25 19
4 eossing the
Sour dataset
node@_ond_ decide whether:
Subsaee~ based on Smaller
Jue compare.
-do_place_it on dhe
oy {ogG23_+han +he.
eT ys) =
ee ar 192199 194 5 1 56.61,98 99s
18-P) Preoadea —1-— 419218123, 98 HS 1 56) 89.67
(22) Postamdes —tt— — 12 193,92 64,56, 45,89 ,981 34.
—O__ Pop, —Becuesive_Staigcase_paoblem_on Input
2 =the _secnsive staixmse_paoblem_invelves. _ Find!
——__number_of_ distinct WayS __staicase_witn given no:
=_when_a_pexson_can dJake_eithey 10% 2 sleps ato time.
—To_appt j—this_problem_+0_the input _nzu., ——— —
a Bray ie beech ha _Smallea_Subproblems i
5 Ehe_tosi_step_token_evas_o_single_siep-.then she |
\__temoinini —humbee_of_sieps_is n=! a rel
RI tne tact slop token ons __a double step.» then the :
| ( j. 2. ———__—_—_—_—-
—_temoining__number_of -sleps_is_n=2 ears
NF sing an wearsive _-fosmuiq1_we—can ota: 3
distinct ways © climb a gstaizcase with 4do find climb a slaixcase with \_sleprthepe Sony 1
| distineh way . dake 4 Slept E
5 22 To_climb_o_shaiacase with 2 sJeps
isdinct ooay. ake | sleps4wice oo joke 2 sleps— ne
= To_dimb_a_slaincose_with % sleps—theve coe. 3..disine.
—twayS_. dake _1_slep_thaee_ dime, Jake | slepand—thena.
___|_sleps 1.0% toke 2 sleps ond _then_1_#.5}ep»————__
o_ —_ eee
Vous aimerez peut-être aussi