DST Week3
DST Week3
WEEK-3
., ..h S ~
pate o
f the Session: -
I
-
I
--
Time of the Session
- to-
. . linked li~t? What 'ru-'e the primary compon~nts of a r:iode a singly linked list7 ..
What is a sing1y tt () • , ,~ , .. -
1.
st..v-
it ut1d,re..c-Honol ,.e_ , t Cof'l ~~ev..St.cl 1n o,,h,. ont- d ~vu.tion
_.J
,. . \ .I .
I
'l • '
I
I
j
23SC1202- DATA STRUCTURES
In-lab:
1.You ~e give~ the _pointer to the head node of a li_nked list_ and integer to add to the list j
~ode with the given mteger. Insert this node at the tail of the hnked hst and return the head noci C~
hst fonned after inserting this new node. The given head pointer may be null, meaning that the ~f
empty. e•
Program: -
1- 0, I5trJ t-~d I P,,, t lb ia)
, . ..S:"'jt~ U'..!~ ~t. . P,n~ert , )')Mt -At~, . l:: . .. . .. ,
: l -. • • i. • 'f"" , I. & f • ' " .. •
l t . . .. .
.SLJJ •i •• ~w ~. (l toit •_ Lf\l l<!l{a))
' .
-
~ht {
••• 5t..t~r.j.· ¼,,~J·;~d; .,~•;.- . , . i • r.. . ,.,· ....
'f.'L '. - ".J-. t ... ..1 L.l).
Wt'\\I~ tltn p
\... ¥\l r -" ! - I':-' • •• .. • t" • I,
.
r •' .,-,. '
.. .
•· •
•'
! I
) 1 •
,
o/r
.- r.
ft1)'.':!
-! 14 I
•' 302-· • I
30)... l 6Cf
Sample Input and Output: f 6 ll s~o
S-30 ltl~
~41./
48
23SC1202- DATA STRUCTURES
.
tr versing a linked list. Given a pointer to the head node of a linked list print each
. . an to practtce a er line. If the head pomter
• • nu11 ('m d"1catmg
1s • th e hst
• is empty), there is' nothing to
r111s is ternent, one p
z. , data e
nodes
print.
kerrank.com /challen es/ rint-the-elem ents-of-a-lin ked-list/ roblem
s:// ac
001<: h
'J
<
• or , 1'
.. . . . I
I
!
{
f~.,-lt 0_' ;/.d ',. t~p~
• c " l
'
I
I
. . ..
{J~n t: t L'' '(' ·'); • .. ,·.
)
. *
.. ••
.. .
' .. - 4
Tu~ s
\6 .
. ...
l~
. ; I I
49
23SC1202- DATA STRUCTURES
Program: - .. 1-,' _srr,;,, J. (" 1/.d ", 4' IIU WI ' ; •' > •.. • : ' .
_st'N(_t {
Nod Pu.J h ( head , "um ).
ln-l ci,+-0 .
..
I
I , i • : "
'lty- e..tu Y n ,
) ,
/ N,, t -rt.YivJ~ ·Cl'leacf),
,/
.... r
f,,..-1: rrJ;r'\ ( ) {
1-·,u lhtQd );
·'
'
J-hutf Nt>~ Ne- h~ k ~ULL,j \rl~d ht~ c-1'\o<k .•
f,,{ ,J,
/
>lon-1- l"' X d ··, .( ~)J
{_f" l:, 'r' 0; f j f-H ) {
f n f- 'li-{ IYI)
Sample Input and Output:
50
23SC1202- DATA STRUCTURES
~ e n t a singly linked list having all unique elements with the followin g operations.
t.hDP
_ inserts element x at the end. ,,
1Ox _ If the element y exists, then insert element x after the element y, else insert element y before the
1 1. ~;g element x. Assumin g either the element x or the element y exists.
;;~ y x _ Inserts element x in the middle of the elements z and y. The element z appears before the
element y. x .
U x p _ Links the next po~ter of the elem~nt x to_ the node lying at the pth positi~n from !he element
bile traversing towards nght. In case of msuffic1ent number of nodes, the counting continue s by updating
;e existing linked list to its circular version.
. . . .
.
'~n~
'
f+ f , • . . t da~ J; - · : . _
h!bo ! -\-tmp 1 .,• ~p-> f\e.:1-t =NULL,
1 , /
~b1e (heaa--) do.fo J~ ~• f- \....1'~ d:li, 0 .
'
. /
{
~l'-:) ~xt: , -,
~+~f>• r
_s~L+ "'"~~ "" -hn,T' .,_ httw; /
'le.. -k.t-,n ,
w~~t. Ctbn-p -) tie'l-c ! : ~uu.} . f
{
J ' •
r
' .
t e, {P, o
-·
tt, \
l \
l~4
).\':\ 1.
51
A STRUCTURES
23SC1202-DAT
ting and end are
not
points. (The star
f critical
f a lin ke d list, Find the number o l points. c
2.Given the head
o
in im a or m axim a are called criticaus elements are greater than the Jrren
al m d previo the Ct
critical points). Loc
a loca l m inim um if both next an evious elements are smaller than
A Node is calle d xt and pr
calle d a lo ca l m aximum if both ne
A Node is
Constraints 105
of elemen ts in the linked li -
st' N <
• 1< Number
5109
1. 1$Node.data ns/CRITLIST
nked-1ists/LINKLISTF/probler
actice/course/li
k: h ttps://www.codechef.corn/pr
Lin
Program:
.-S6I vt ( "4k •
head ) { .,. . ..
:,, t
' . •
. .
. . .- . .
j . I
. ..
)
"l"°'" t.,,fkta1, .
,I • ,
'
J
1_!p
r~ 3 !> ~ · s
,3
.
d Output: . , :
Sample Input an
S2
23SC 1202- DATA STRUCTURES
. •.
~'\'~\~ kd llit N~ WYYe__o-l: ,;, tt t,/
'"'~ l~ (tu-r, e...Y'I t} { .
. .
llf~t/ I
.5
Sample Input and Outp ut:
Of p : I/ ,. I I Lf
l I
• '
53
URES
ATA STRUCT
23SC1202- D
nll !JJ ,
ou sho uld find the miniz
d list. Y
g o rde r so rte d singly linke
en a increasin to x.
2.You are giv an or equal Element With • ;
g reater th le me nts.
which is o fn e e lll(q
k e d list bu ilt on an array xti that is the index o f th ne~ e
ngly li nd ne xt i-:/:
y, there is a si is element, a
More fonnaH is the integer value in th is the last). The list is so
rted, i.e. ifne - 1,
e i e nt
integers: valu (or -1, if the current elem
st
singly linked li
i > value i.
3/B
lp ro b lem se t/problem/84
m
codeforces.co
Link: https://
Program:
. . -
.
.. . ., ' # ,.
••
-
.Sbu{t
•
I ' ...
•• : •
"• f
.; ,
t I
·~I
I •
. ' .
.. .. '
. '
• •"
I
. -
'
4 - • •
,
j ,t
• ' •
•, • f
t. • • ' ' .
'
. , .
t and Outp ut. •
Sample Inpu
1 •
s
-1 8o
S8 r --1 qc,
A . ' •
lt ,
g, ,
n tation of the linked list. You can cho
•go your 1·rnp.1emehould have two attributes:
.
val and next. va1 ts
. h
t ev
st
3.oe~• glY linked h st the next node.If you want to use the doubly linked list, y
5111 0
in a inter/refer~ncd~ t the previous node in the linked list. Assume all nodes in the linke
is a po • v to in ica e
·bute pre
attrl
inde"ed.
roblems desi n-linked-list descri tion
"i,, t \Ja) ) l
~bJ -> ~-th *;
P--> '-h 1 =-- \to\,/
i tA-) lfll li-ed C!J l)
t'\j tf" ~M ~Jt * (U'n Uj t Yeole t, {
~j tfr\ k,ci tfJ f * obj (_Hj tfii kd Lf..! 1 >Y10 ,10L (.s'-11.~ o/ (_m~t?l\~Lf.J t))'
/
obj .: ney{. l
.p ,I
,t-, I
,I
• . \
• l '
e, Jp : u l\. , "'o l t I n u l t] 55
23SC1202- DATA STRUCTURES
.'
A. ,. •'
. . . ..
••. 'I
. ,
.. .
B: • >
c~ e:.
e generated suc h that ther e are. no ~yc les anywhe~e in. the entir~ link:~d ~~
The test cases-ar
of-two-linked-Jists/description/
~in k: _https:/~etcode.comfproblems/inters.ection-
.. . .
. ¼ipt+ ~d A; •• ,,
Pro gram: '
.' .' ..
- Utnp B = hea d .- • •
Jfn.uf I
I
~11)
fAJh fl e Ldf ff :>o ) l
. .
p6 :_>'
·,
:'_ ,-ternp iA (
ne-,t·. . . , : •
w~ lt l !tmr. A!·~ ,..rvtt) (
./
' ,~...
do./.-1 • ,. • J • .. •.
r~.J#t . '+J , ·~ . . , -.
.'. 4
.,. • •
'"
•
l ~ • -..
4 • ...
•• •
•
, ,
J . ;
•
-} ne..,. t•, . . . , .. s
_) ' C
~t • t-fiddle .S-rr~t., f
•
..ltvut4 .,. .Slew heod , •
,f
Link: https://www.hackerrank.com/contests/ds-wee
k3/challenges/starting-from-the-second-node-delete.
alternate-nodes-
..
Program: - I t \• .. . ' '\ ,. \ .
\b16 de\o{t (St!ott
• . .f ~eod) . I 0
\ '
~t ~at d !. NOLL)
I ' • I l
.•
~e (~d t),
/
/
. ...
. .. '·
, . ..•
. "
.. ' I
Mark
,
s Secured: . outo.f
\
,
Full Name of the Evaluator:
I
58