Data Structures
Data Structures
Linked
ist |last noda data, Stiondlastdat
Thsoisn,middle elorntn,
Delehon,HeVGAYE, inktoaedhon
Menaelinked iüt, and yps
o inked lst.
Chapkay ylo2l>Shack.,cqpplcahon, implerment
s to as
Shack
Cnd.
Tree,Binag Seanch
doleion in BSJ
alezlp2y
alosl2c24 AVL Teee, lbSeoahngin
AVLlof to126
Heap, Maz4 Min Heap,
onkakan , Heapualgnana
kxpuexsion Tee
Chaçlenb Ja)loalasy Giyaph, qnph epltkeottson 124 4o129
Adjacenty natiA Adiaen
Graph Tauehsa
Coder Asimy
Aaigoaont
2198
231
292o
2
46 o 2121
223 232
24 2
22 2
(moo1),
Ix240¥21x2
=
- 128+ 32+4
JSS
Corwat deinal to ocal
4
33928 Š12433
3155
89 3 813
(s)
Q314)R333)
Conuent octal to deima
842+8°41
32
GS2
31 AE2E
3479
Dayo
lechte no –09 Fouchat and kuedo Qoala
end
Subhrac hoo unmpe
shant
-Paxolldogrurn Any
Ar
Read
ab ab
Read ab
Read
2
Point
L Hug
end
Find Cube a num be
Read
Read
abe end.
TNNC inui Chatk
S E Read Package
Read
han ookh
deusion,
&Padeage malhlng
Vint
Rejenke
tepled
end GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
Reod mo"
n.2o
Read ohonuose
Point
egd end
Fnd biy no (}b)
Read a.b
Snt
Read then
ab
No A
grede greot
end.
Yint mo m
Hm
num
Read m
Count- Counttf
toant
Ruint m
mauNal no
Shautk
L23, 4,5
Read mum
Count (ount t1
Count
=1
(erd Count
Siant Dahrtn
Road
Count
tt
Sum-o
Couh SumSumt
Ln
"svmGtY
end
Sum
Wite ou.
Hdd digi
Cout
Clam Aolhn 6
nom)
246= 9
ohile lo6S
m=o)
Hhin
Lenp ye0H
cloa salhon
yeharn o toy (ot L9)
ínt ísleapl int )
olhe
i
Revenae
ijege 2s4 432
579
diuy to
Q34
taryNT
Hehan
INT-MAX
Mehunn ENt-trtt
10
ang>NTMAX
216
2
2
2
Raic'
loo00
Gshile
/n!a)
n233)
jatno GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
(onj ==X\
hile(munm)
3
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
Dl L
DATE
PAGE
GaQanmant
2 13 CoMplemet
26 21
3
21 23
Aiblic
'
Iohile (n)
\00
Houo mnany
lemend
o
indey to S
lo24
-S-u-2 -2 -I
=
add (aEs]) lo00t 30= loRo Ans
PAGEOY
O
Chapla2 20 Array
Rouo coise Store olurMn Wse
Rouo-me(o
stoe
alomnmer
-order
0
2 3
Rou majoroe
2
O1 2
indey = 4 elemest
yeAy
() Soabe
index 2:
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
O
2elemens.
Hoc
=
eleme ht&
t Llemenk
Ne e olemet aboady
2 edement
2 element alasdy
Gilled
34S elenn 2 elemenk qlsy
Loo0t6&s lo6&
-3 -2 -j o2 31
BA=|900
Sel
S-[-S)-(-3)+
toihin
and 4 element
925ye
=
adilatJC)> looo+ 92 log2
2
-7-6-5-3-2-1123456
Que a[-s...s)4.. -
Kelemen
-3
alseada 9-(-) +L
L Iboelemat
-tnev
a[NITNT
add (ai)
Li
=i-l-ot
Totalslenent
aidy lled
GATE CS & IT Study Material
elenent https://t.me/gatecsitstudymaterial
DATE
PAGE
23
int a1C3IEMT
2-1 ayay2
to
||Tb
olemert
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
Og
PAGE
ue
Rindes
elerotnt elemert
iodex! u3 eement
Rled
2-0
-1-ot element
2YS:Io
S-(-sIt[=
Ev eny indK
(alement
lenernt
element
alement
ndeX
24%*L element
element
-S to-1 -
lo to -sto 29
a-l-s)+{ =-(-10t of-3+2--s)+
elemer
S2*4*||
19122
20 na CalumnmaisY-de
2
902
a
Int l3If4T
BA=Oo0
Wc4Byfe
Col uoith indes
Col uoith
inde
2-ot3
-l-0|=2.
3 elermen.
ql31Lnyindoxvep
2bjte F33]
BA=lo00
addlaoo) Tecy irplexindhisdin= 2
add (ao,o)
Indexalo indexo
Liled-ol
F-H-SL
9X)2 elomonh
=
Total elamonk aaady (illsd 3A12tr
4| dlemen
=. o82
RNO
m
nde mn
SpawAe Mabuix
Lauottiangulo fnaiK
msbúx
iiTi-diagono
2 921 a22
33434 entie
Q12=0Q=0 34=0
3
RMO
a
only non
Zero enbie in Roco ma(os ode
atT LsX ot
Passible bcz LTN U quaze mabmix>
qu2
a21922
add
to
2 alenen
3-\4
elomant
Tahal=
ft2elomany olhadg
t- dements -8
Gilled
()
index 1
toi- i-itl
2 eernent
Assore
31
Gue
add
S.sE...
Ai,-2)
al aleady
-5 to D
lllea/
clancnt alboadyt
-3--)t)
=
olthin
3l.
lement aaeody
=. e
emen
F5-3-2lenen
Roc-col
2232)9ve 952433ussu4ry9ss
alamend alesdy
biked
blatolbasdyle
ti-à)
indexiN-(|-1)
index2> N-(2-)
ndex 3
N-(31,
V+(0-)+{U-2)t--(-jt2\
2
Totl elmant
2
2o--l[20--40I
Qo-(-20)t|
(add ale1LSI)
Cal aloead filed
Oithin cdindex -6
clomond alaady lled --20 to7
l gum
Col= uo
=-26 grd col = 39
lt4|42
=
463
2
EU83 elomed
X
X
addl H(BI
auadyied
22elenenk
=
2elamnt
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE IA
3.
izaia
Roo ma
osd4
2
ohot index
(s 3ielemdlrest
Bi
ed
=20 a34
=9 leet sentey
-
row
Total- lo olemes
byenaal rnula.
TM n RMo
2
- 432
2
Nenoxy abaady led
2
12J[-12--
AL12.-121iz12 AL2 12]
ele h tow
indec boloce Ao,s
2
fo -1
Toal elemen
alncad, led
23
2 12
12 2s
GATE CS & IT Study Material
Fist + (at] https://t.me/gatecsitstudymaterial
DATE O
PAGE 2
add laus)
Loih ca 6iled
Soo clreody
-\2,3,4
F
toodextoR 424R44o
3-1tl 3elem joelemert
yrhcel cal
-
Total |ot313
mai)
diggons
5Main di agenal
the
belo
3
Hddementin.
btouo
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
2L
nn
TGtal
tidicnonc mgloix
Totol olonond
Rt2 Cn-2)2
2423n-6
clement in JiaLO QXeph (t,late(3)
U=3S-2 3 elemcn
Tidiatorna) in
Ro
lem beloe ays
Col- &oWt qy4
=2elonent.
3d Muq
a23 |32433 434qq3
=8element anaz2
Tofal 8+2= lo elem
(28l 2023
Qanstonttime
Rardom Qcced
olement in
Cache iendly poxfeamante incea ed.
Constant
lime
One
Foli=nb-iade;i--)
6
Al=H31
o 2 3 4 b
2899
Ne Tasest(ooAtindex
indek- dalae
ojndeto
Seat 2
[6o 20 3o4o
2
seo glém
S
Qdem
2 GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE Z
PAGE
Sieps.
Sloata, A3]) 2
2eleny
22 n
3
eisgi!
Suonp(HIJP Ln-i-1)3
oddno 20 bo
Gn ) 2
t-) -0-O,6
Suogp
Soaf
3 6
Boaplatio],nhighl)
loLott'
Repe
6
Do20 3p/4o So
5high
bo
Sosp(Aibu], ALhg)
hig h
Sonp Calosl,agh)
Doo tt
hiah
2-6 ol2o3yoso66lo
20 30 6o
2
(e-) Hevey e
20
(ai2,s) so
Heser |20| 1o bo
2o4oSob6 o20
2
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
2J
no
May hl
toe knou maxrsNA2
Sohei
hen
nith a olemena I he
bave
eoch
no elanent alaady{iled o
to6
Nnoay aleady
Gueo.
cnd ina
of aomonN
in acay
So
Smalla L
langusl.
QSs-(-122) +
1
=25s+ 124t
Geg
each elantort
indeg gaak yom
Sol
BA=(o& add a ]
No damont alxad, \;iled blone a[a= idek
-ll to
Conaidn a 20
-13 12
- -126
QSSI27 t|<883)
olorma nt
Noo(0= 3
-(-28) += 32
+1
Cach iadey n
thi zolndad -28to -4
tio dimen= telon ent itd-17429
1247-84elornert
|29---222
Sa
&y
aHa 625 ond Sie o each domenu
m
e a
Suppoe elumord stosd
us Co to 4TAnd
Lo fo
Atetd in Cmo
Yho slomonQua
ppaje
l6eloment
Seoch indey
-6to3 3-0t
5-0t1 eltrme
C-6element xI6=64
alo9dy
Tofal= 4t6=to olomont Oe
to Ans
od
Considox.q Q0 cgoiay aor L- \s4--
-
3
fo
-2-(-1+
-2X3elsmont
312 damte
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE 2g
Total olamond
Considu on
matix uppontm
that Arone ain
hpn iangn
Lshone
-7--t=
(
Jiuti3tl2t1l----2+
an
colhinrow
AoDabaody illed -ktot
alamonhalusy ill Ir
(124342Y Tötul elomornt alioady
lk oo423
GATE CS & IT Study Material
323
https://t.me/gatecsitstudymaterial
DATE O
PAGE
So
Hal
colk
biled -8 to al-6)()
-t-(-8)1- -7t8t ColRow
20
>31elamen
ioder lem
alhadyiled -3 to o
Totl alonont
and hol domont (5)Ag
Ahored
in a
Sol
Helcol=7
Inderi
F22elemt2
Totol oomand
Anß
k23em
42 Bye 3
Soo t= S12
-2444(ls loman
Tokol
2
KX
ioked List
stud
Cint i
int
memorn
-attocote
Noid main)
tnct my shrut S
Sj-1238
mg-sbuud
Q
int
intb
Membeg
Can be
Pointy
Vaable S-as1o
Sorm
Sb-Sa
Rointen
toirieg
Shat Pantko
int Ptr
Valid Valid Malid
Sell oalanhial
Sunnd
Stue
Ranhka
PAGE
9 20
P
3000 Ptr
Suct
Pan kay
Typevor
Yoid main )) SL
Sp
r Ptr
4S S S
Sg
Linlred >
List
Linked iat linean oat
ahich Collechan o
eonent,
Caled ohich node
Conlain 2 pat
data
linked dit
a
2oBocoo
Node 3o0oLL
'o ype isa collechan
enta.
o
o
dilun
don
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
Racbler
Maid hain)
maloc help
Nede
Rir-maleclsp lliat))
Shruct uode
VLol2 lo12
Heap aeA
Ptr
dota
L
Poinjeto Sirutuneyariable
Houo ho aciey mernbeai \xann penker
toó
suhun GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
Fore next neo STH
RT 1 Special pon a
DATE
PAGE
(* Rhledata oR (Rhrdaa)
OR ptr neyt
st node
dat cata
Bo00
Ned Ptr
Sbet
P: Rointen to sutune VaHahe
Pty dala
Qtx net 2o00 (add ol Setand(odlo
2000
ade Node Noda ndede add
add
odol
Stbrt Nodo * START:
I he inked
ualid gddran
START
IeSTART NULLcilar
Linked
dit is enp
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
NULL
daty
DATE
Null next PAGE Z8
START =
lo00 Hxsk Nodo addaM
Loith 2memb)
START data
$TART9 Unk
datg
is STARI
linkdotanoda
START
ink
hode addO
Ünk
START Giloba
Gisen ainiked
a
it qiuen
biven linked Jistaizune it
START visihn oath elomat eraty ante
data ünk data Gnk
o0ovalíd
alid adday
Phr START
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
saut Node * Qs
Rr= START
uhile tol=nOL)
Node
Staud nade VaidmainlOL
int dot 3hat Nod*
Strud Ndo Link
le
tt )
jnt countnodel
rcgarn int count =o
ohile ( QtaNoLL)
Counttt)
Rir Phr ink
xohun count
lat nedo
Giuen a iaked onk ha dota
ho
r
= True true
loniletolink wUL)
Print Phdaq
his
nNuu)
stat ededata hile(hrink
hen
lat
node exit:
Noid Rninlay)
Uhilel h
linkl= NOLLY
loiat(y.d todato)
STAAT
(ink data Gnk
data inhk data
2 3X
PhrnkúnknNULL3 faye
=NDL |l<TART (inke<nlo
Thadt Rr=START
node Dhile(Pik ink -noL
LSSTART
rr
surt NodoetreSTART
ohile(phrlULL)
Phr= Phrntk
a a code to
Guen inke itik puin akani
STAAT
2 3
START
otrink=doL)
Tnseakon ad Begia
bynd
Joo ac Posiio
Gnk
it ull Gak
daa
3oeo
data ink
Skuct ode Pt
Soe
(SheatNis
add NeNode
Sooo
Inaet at Bogining
(cdes
Neid Tnsed.at- beaint koy) STatt
sNOLC
START 2 pityyds
=
key
Îs
Grlobab &vey in ked ist
2 is empty tyillcoork fibe
START
uhk data Unk data
Stadeno\eco
Call By
STORJ Rofarene
-in ota
Pir data únk
Variabk2
o
STAA
2
e Znsentsoe at ehd element.
STAR
Qo loox
Ptrddafe=key
vodo (reae (ltode
lin kolluafi
CoxeI enpy Hhen
S TART
=Ar y
thavese,
Case I Cnkedit eot mphy
START
legt pt=START
1ode Lohile (t inlk-NOL)eon ptr inke komp
Cde.
Node* ternp*04 Libile (Pfr>nkl-NuLu)
Ssurt ink
ten= malloe( Sigeot (StrutNoda); Ptrs Phr
Ptr =
START
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
Counh Noolo
clan Scluioo
ol inked it
Pubic
int gelcount Shrud Alodo*heod)
ptr hea d
Ptre ptrhext
?
UHehtinCaunt
Llor
=
Jemp mallsc (Sizte(strucd Ndocl)l
5CheadNL)
head
ptr=
Pr prext GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
Dohon hood
chue No o4
aa Qinked Qut
Ending mid ale clanert in
iChead == NULL)
Slo=Slo next
fot = nex
fat >hext
Dalehon in inked
Delehion
lito
(om bean
Delekion
Ddeke
hom tnd
lsm begin
(do noling
Siart
Jo00 GATE CS & IT Study Material
ree https://t.me/gatecsitstudymaterial
DATE
PAGEU8
STart
2000 Booo
Noid
STARTNoL
Qtr= TART
ond ode
START= STARTS Next deres
STGRI
STARI
ioNULL
Fee
Coe2
my nked lit
Pals
(STA RI =NDLL)
(START-> Dext
oAe
Ondey.
Biaking (isked Oat in Rewese
Oinked
it aal Reueae
Rastaing fexible
hen
weye
Prev urent
ÜuuH head:
head
htsd,
hegd=NULL)
Sa slaanegt,
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
qbsolute is like Mode
DTE
Ls for 4ve volue PAGE ST
head
nerdL211
Peint
wohile cphri
ptr =
healn
elhe il (Ca2)
Phy= ph hext
pt data,
9tehun
Noya hen
tiven 2 Aoxted Cinked lit
Nodo* Sohedteug2
O
Alade* head
MeMLSIn Q
=b> dako)
1(adoka
head lot b
qsa>nex:
ole
lechne No - 06
empta aa
excHe one elemen
he lis is un oeaauing r
AO)ed in
20X
pdata neahdaL
P=null Not Pnet= NuL Not
olollo<sQo).
Noo &inglenoolQ
a
singly inkod y
SAeVeNAe
Spate 9 itin
Contant mamog
Oimked
LnaVaxioklg
m
elomerd into an
nainkaing in
14243 -4(h4)
mng nn
Assumina hat point tolvala
Nall Jetninatod Tnvocahian qJon uill.
Append ut m
to he end t
nul poiake doagasnce or apged
it
m
to he end
poiake
istn
dleaahahue
C Cause
peand list.
head
head
Qmghyensipatod
Vae
SinglyCinked dait
Douy
Cixculon
Heade
linked
Unked,
it
ut
hed
3e0oo/N
Sbauct Nodo
Travyat
nt data
Saucd Nosde
net
Staurt
SUuc Ndo jemp= malbc
Traueuo) in CLL
i (heads=Noll) eun
do
PAGE
Data sxuchune
ConcHet vieu
Alostat view
Imglthmantahsn
No pagnakmialangquag
(iiD
te falk anly cout eakne
and cpiahanh delincd
Stak
Stadk i a ineoM dat stuctue
(10 Tbat uo, on lat in \int out policy(I
Folse
il stack is not
ToR
ToP>
-detete
Hpolicaion al sack
Recussion Fupcion
oy
Taiern ol
Hano Postlix evaluo han
Kalanted Paxan thesu checkinr
Tnlix to Prehix
added elstnant
bo
Tol1 fo 1o 30oSo S
3
- Sige- reha
Void Push (int ) SiArof
ushio)
Puh(20) Toe- Totl
3 ot
me
Consk
Pal)
To | 23o So bo
2 3
Po P(3D)
POP(ac) INT-NUN Consont
6) JRmp STACK LTor]
ime
ToP--l
ToR
STACK Yoidmain)
Shuct
Shouch
int Aor16] STCK SL, S2
Si. TopSg JeP
=1
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE 6
Stak Roamutaon
guen
tohat could be Baible ode) ol Po ( stack perms
slack ponukahan
Popc Velid
Al3 Ruhl) Push2) poloopU Aebl3).uyl4),P20,
Valid
2,1,34 S pushiil, Poshla Poe,PoR), Ruyh(8)_ Qo2(),.lushl9 Pop),
invali
S
esh), Pahla), Ruhl3),.Ruhl9), PoPu Ror)Hf
432
bekone speand
t 23spen ahor
is
alken cpenand
astlix 23t Gpenatox
is
posthix Conuen,ion
To
sng
Stak Stack
24[85*]
+
Posshix
235*
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
oen)R-L
L-e 7, X
DATE
PAGE
QR4X]/C62 1]
2+(34x 621/)
234X6b21
-
inkgX (atb) x
ch e1nglh
(abtcx1/d-Let1IJA
[abt CXd|e ArthlJ
abicydelq1th/ -
Using Stak
iníx 2+ 3
XS
235X+
em
oferato
(e inbe
Vetiv
=
2.34Xt
inl a4byc
u Sing
S0ihout
0Sing stak Shack
+2X3S
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE 65
CIx+abcd]- te? Bgh]
-/x+ahcd
efh
Ex Reverse in4iX btq
bat
Reuene ap
o|p Cb€t
: 243xY
inlia
43X2+
42X3u
inlík t(brc-dle)
e A4
dfcbx-
eVeye
inlja A+[eXcIOE
no 203
lehe
Houw to evahate posX
Voltlia eueluahon
uluchon
Stackh
hen
Puh reult onto Statk
235Xt S, 3
+5IS 2
inlj 2439-6/g
a
2 Hpux-62
Postbix 934xt 62]
12.2 12 \HPyh
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
Cii)/: 2,6 =
(o)
Scan (el to Rignt
R3X9t62|-= 242t62= 2+2 6 2/
- =
14 6
2- =9 62 |93
-ue.
284 direst solue
213
2 lebt to Rgnt
a an
uhich he nleocing ís xenhia tto conyent
inx
en opengrstatk
An 6pexnd Qack
An apeastrg aeuand Stack
Ppae tree
The (olooing SegsieNAo a opahian pe,ormed an
Stok
Io 2
Arst Pof
\allocoing Qernaohon on be ctaioed
thach oh tha
Stack ouming 0zdo2 hathe
hot
L234S in
Shk Pemutah an
,PuhaPef,Puh)Pe
Pash))Pun(2),Psb(3),PoR
S.2,3,9.
PoP(2],PaP)
B4S 2,
S3,2
This u nat Valíd
Ca)
mony pesmurain
picgsam atermp to gndsts oy
A h auhing chaka
ponibl the
ol stig ahc
PoRa)
Cabd= Rata), tuhl b), uktel, for(),
The
abc-dep
atb4 de GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE 69
The lollocoNg Qotix
eip with siogle digit operand
eynbbod yinga stak
Q2342 37 ts
Noje hat exponeniah op enator The Top
23 A23x X
S,
3,2 A-322= 8
4m X
32 2x3= 6.
+
Aue inkarsinl
S
2*332+
lo 3
Hag
yoor()9
Caictf(clopO;2
2 -(S
(- Right)
9-4)63
(unchin
A ddined an siace dint sahse fhe
pillasing Rapedy
=oAPuyh(s,D)
= mar(AS),ptitor
al staks S and int
baat stock S ontain int 2,-3,2,-1,2in
IIa
6
Smax (2,0)t3)=-)
=
3 eleuhl S,2)) naA(SLo)+ (ol
=
ha 2o) +() (O
3) Au
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
Qolir Eualuakon
3 X S
inljx 9t
alix t2x3S
Reyense pliy: S3X2+
AM
Reciion Peoblenm
Ls Standad oaoble nm Touier af tanai
m
ond
dik
a ditinct sige
each
Taget : Move
qll dic
trom Souee Peg
deshnahon Pea.
Cto
Sonce Aualang 0ahinahan
Sn=3 Cdi)
plake Qhave Smalla
we can not put a lage Sige
Sige plale o
disk at fime
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
92
2
A
A
Sourc Aux dohnahon
ToH;SouHe, Dat,Aux)
int main(J
ToH 0,AR:
ToH(3)
ToH(2)
=
Int no o uncho all
JoH( m)
ToH (n-)
Tonn-2) Touln-) M
Ton(n-2)
Toth-)rN
N
Ton(i) Tonl) ToM()
Thl)
(G ntunl
4Auncion al =
+e+24--+ Sn= a()
2-|
Hboonacci Sexieh2
ix
Fb (o)
Fb()=
hbl2)= 2
Hb (3)
=
Fhíg) A Kh(il= ltl=
jnt
1b(8)
Hb13)
Ribl 1
ibl)
Fbl3) 613)-S
Let
Fblm) Cal
Hb(m)
SHO)= H(n-)Hn-)+
HU=L
t 4
tls
2.
H(n)l
Sum o Vrevious kwo lent
hat Total mnba) c oddinan in Caludshg bl
-hotiban
Kbl)=O
=
Kbl3)
(Glo Bbn)
)o | 23 6
4 S
ploro. in hbln).
Qnene
ineo dao stuchne
Erst io hcst ouh
Insetion ea
Fyont
Simple Sueua
2 3 4 S ist Raasi
Rear.
inkialy -1
lnsenlio) insent Ras tl
Insea (2c)
Tnseat (36)
Töseat(Ho)0 3
Ldelete 3
dolate
dáete: frot t1
O 2 3 4
3
ront Hront-Rear
Rear
tohen Gaeue
hont Reax
-l corner Duou
LUben hane ú only in
Rroot
inserhon
Lnaueue
void Enqueng (intz)
|
front
Deauene
Con not deler
Yront
Dequaut ini 4emp'
int ()
aleol
Save etomen
Ront+t
=
elaneni Rern
Front Reo
ese
Citulo eue
Vous Rearo
Reay
degute 9
yeue is att
nquouolao)
Reay front -1
Enqutue CGo)
2
2
6070|o) 4oso
3
o2
Qeuer is
Reax-D
Qeytt
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
0C
iCEenk 2- Rean
hont Res-L
Rehun mps
=
olie (ront Bizt )
ele emp =
Gucee CfuntI
bont tt
Jeshen mp i
pioat ilth is
eloment
Th haue
Coe
Yhenwl
Smallno= Hightnoah
no
larqe
head
an aoman krom
V:o
Doe an olergen from S
Tof Tof
The Tof elomenfo Sadk
an
yi addata storage GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
Head Hed
Cnquoug
2\3
TB21T
82
S poQ
So21
The
SL2
GATE CS & IT Study Material
-86 Ay https://t.me/gatecsitstudymaterial
DATE
PAGE
A qyene
impumankd waing
inked
bainteh Shoon In nss od e n donok d
igu, lat
in the Cyoue. Le hqyouo be inplonanded byintenkna.
oRUS Dote at
hed dquOLO be implemerled a
hod
Shich one af the ima complxiby o neR horo allden
q as
iuadon Guan been innglam orned wing sSigl" inked t
I only only
Considonhe
bnany tee
S.
remouingit haom
ne Tog
asihout
Considoha algseihn given helou)
not Smpt do
Sis Empk ag To( Hea (0) hen
X
Qush(Six)i
End
jdokor)
L2,3
:,2,3
incteoing 2,3
Sack 2 dt
312 Tof
2,6
more ovo
9 tenahn (ineoing
ye
elem in gtatk
grd ienaon e
loz)2029 (Sahuday
C'inocx5
Dinetoy shuctSte
(20)
Pae Tee
Sinsy SeNch Trte
B-Txee Rt Tree
a
)Node ' Each elemenk depleNent ky Ncde
ohld
(ea node
child)
DATE
PAGE
the o
no' chld ol aa node
()
the Hhe node, in ht alh
aÍ
lovel= 3
iS an Oncestor. andh
Pasent
Danenh ol Some ancestesiado an ancetor
on
20 Bo§o,80
20|oO
Jo, (00
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
3o
Bo) dexcedent DATE
PAGE
Oeendanl ad a
nde
Dode 9o and Loo
parent
Silling ode
iblingd
8,3,86
Siling Qus
to Samo gonaahon
ievd
o nee
node:The numbex doxendontol
MSgeoa Sihe
induding ho noda ikel is called
ha nodo
node
Sp a la,
LioaagTaee
Evoyg node can hae athnost 2
chid
O-chiid
child hode Can have
ink nafTi-
ndde 2-Child
This
GATEísCS not&imgIT Study Material
Tree b
https://t.me/gatecsitstudymaterial
DATE
PAGE
Nidnode
height =2.
FL Binoy ree
hat ho moy no
(evel
teul 4nod 2
h-3
2
2 2
2
(IS
Night h
he2
Roo
Let dota hiaht
NOLL Yooo
Nult Bo/
nt datay PAGE
9O
ha enctuy 2- childs
This is 2-ar ee
This
is
algo
ree 2-agy Tsee
no jnkana)
hode
has 2child
dary Tsee
J2 3424)
2+ 2t 2
Rea
has exaty
2
To tal noo
eoch inkana
hoontoono)
Cbild
o 3
nainkanal neda
(k -)It1
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
L-1= k-)1
deg:2
R-l
A Bina
tee oikh
degi
2,
(S
daree
m=2x2t3XLtl
inkanal nodo st L= 3
8
J Root
201
Root Rol
2
3y Right
Subtsee
Rrgh
Roct
ínozdon
Right Rost
|e,213,S3,8
Rse
oden3 A80ECE,GI
Yaid Qacorden strudt alode pts
=NULL)
Riaht("APhr> daka)
Inaude Taueood
aueoe t d Hho Yost Dodo in Jncode
Nisil PaceRoot node
Right subkeé ol yect pode n Jrenta
Tauerie
Node 319]
2 d|i
Tnosda 0,6,E,AECn
Post oxder
oEEBHnCA
Vaid Qostoad on (Staud Nodot
Ph)
(Shape/stru duae|Topoeg
24
3X2x 2
-KSxx3l S
3+1
Rey' le,263o
inktaasked in labellod binoy Taee
\O, 230
hnay 3L
Loith 3node
hcice (abeltad
GATE CS & IT Study Material
Stouce https://t.me/gatecsitstudymaterial
DATE S
PAGE
No
with
Oue ouo many binoy tree axe poible
beosdon A,c
hon Stuckue
(shushue
-
CARCBA
X
shacheo
QueNo oh binag toees possible with ostosle sc0A
Elactys ne guer
gjuen dxauea, al (irsinfletl
mdongth
No
wimbe
c
lot
A)
Sol Re
Thozde AB
X
Yostocdea nlag
treeaim gieo
20
ue
IalReb) 2624
Root
Riant oisiy
2 nod
3 node
Unode
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE00
max no
h+
<
Seoch Tree
binoy
Giuen a binany Tree Y a keu_ nd chehea
prent
(o
Sabtaee o a
than X.
RTH)
Aue
Hhe Somo 6den
o Roo|
Insent
Inseat 20
(6)
o
isealhng
inseahag
Co Both
Boh Tree
Tree ase am
=SBST
nt
kegs
lo2,1t130
Yseosden lo0,99,8o0,9r,42
99,i0 o2,)3o
130
130
(too
m
ith nada
q
bimy hree
sthe
and alo nIroy ag
uen oo man
lo, 2,Si,&
incrconing ore
olh)
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
keysgo
Skeuoed oo) 4element4cOmpaisor
Tree olm
thh Cay
loosf
Dele
Seash Tree
ion io Binag
-Case T Ddehon
oa gode hauing O
Ô -cdhila(ea)
((00
(92
re 7o (\ea)
se need fo sdenhly he 'axet einhea
Seach
hake
(160)
Poine
(20
Delele )
(20
hensdo
(i60 hayRglate
dato (go (key) to be
dolokd uaith he
Hhen
deet 9o
A-Roplel he rede
(ka) to be dltd
Loi th minimunkey in
Hhe Right Subreed
(86 (95
delehch
(Go) 32)
tveto detete
qnd
min keyin
Replace 9o boih
Righ Subbec (92)
(92
(lo
o a bode am
L Balaning lgtox
fador
A tree AVL Tree
DATE O
PAGE
e Canhud an
insehág(30) () -2
RaR Rokahm Reguicd
10SUt &
t LLRoaho
(20 (fo
insent iS
1R Rolaho1
Angent Jnseat 3R
32h
(20
R
((s
R
RPRolea
insent E
LR Rotoho
Inseat C
E0
(e) (Oa
PAGE
RLRofot
(B
k
inseat
LR Roiahen
|o, 3o, 20
R
Gues
)
t
Re
Inset LR
R 2
R
This is AvL
iee
-4
hoda in.
height s
m(b- n(h)
nls)=n(s) 82
heigh
DATE
I
PAGE
Hea
Max Heae Nin Heap
A
CQ1 in which eVeny node
Sahsy qpopeg
node u
gtaneh han ik hoole iS Snalle Hhon
tt
childen cailden
C2
L
(2) maA heap
Nun heap X (1o
So Not Min,
Max hesa
(mlog hea
60
YEAP
n o
inseat in heapnith hode osn)
ee Repexen tah
2
index alnodeleo =
26 (43
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
tn Qrray
DATE
PAGES
max heaf
2o8s6S 2
6
Giiyen Qn
so 67o
7
Aue
Hexpiby at So
indexle
Heqpby
2 (so)
index
20
toSo 6o uot0 oO
3
Hapiy algcaihrs
langzat
(argat Right
2o2y
Lechne No08 8Feb)
Inde x
=
Dodo
(2)
One altor onolha.
xdon
Build -heap by Heap
2
(23 3o) 2
henpila
)
(jo0
Nade.
3) (6o)
Canbe
ind in in maxhtap bn
HINheo
A
o2o3o4 60
Had nin
in mhea o)
Hod ma
in m)n hop= DlD)
delge álk, 6
dodeachO
fnode
deletkd
6
Delehion
Toseion ollogan)
Seach
o(L)
o(m)
(19
#o nax heap
chaicedor
Root I (MaX
lo,20, 3ouo
outd S5Sekiam
0,20
(uo)
1X6Cz
f2 X 2
3X3
=
T) Lx
Rght
operand
togi
operato; intrn al nodes
qybt
travezya°
lost Ruisxit last)
Lieoatriaty
(eat
43X2t
SI3+bo90
Si36
6o00
243Xy
Reuge :
43X2t
6)
SI2
)(ec
op o
Ehando pesnd
ohich one o
ha hellking Seqllene ohen sosed
2344 1Sllo13Lyl2,4
8,9,613S23il
taee is
heght ol, sbce" hioany GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
24
S,
lotos 8,9,6,1, 4S2,
Same
Inorcl 8,6,3,9, A,
2, SO3
biyy
quen
In hos
we tsee wh
SDany Cngs can pulsto Yhe
Range sato $3
8l,s32, jo2, u33, 2&376 3
S2, 92, \2, \99, 242,38L442
142,21&, g0, 386, 345, 2?o, Ro3
Sso, |u9, So7,3S, u6g, 02,29o
hae ntned
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
J25
Searh 31
(S2) <293
g)<27R
3S3)
(21)2243
f27
no-forbk
Nor Poible 379
C248 heck
brall o
de
Taak ohy
Thiy ScqsonLe is
fowible
(20)< 275
2732 Sso
not Posbk
Lonen
containig ko 1,20, 4o, So,20, &o, 90ao tavea
giuen oxdo MoLo many
paibla inohuch Yhaxe kay alio
neda (ontaisir GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
1
PAGE
lo 20 RT
Wever be TraveHed toj20,o NUeN
60 Ao, 8o, 90
(1o,20,4o,so
Splace
Seletn uplace
slo209y
6
Chaçter>
CuRARHS
ej= U2),3=(a13)
ualL(283),39,(134
Garagh Ropaeaena hion
Aljacent Mataix
Aaiacony
ethe
0hea'se
A
2
edge Hdag (i)
3
Lüpen dintrhed
Ghoph Sparse
penie
Nede
Adiaconcy ut
(
Nede
O,2,3,4S1
2 3
distane daytone itune
dutagee , 34,2,S6
GATE CS & IT Study Material
|,3,2,4,61
https://t.me/gatecsitstudymaterial
DATE
PAGE
6 3)
3
1234s681 Depth
ronm
st
shaxhing
18\Fb 2o29
Chaplox
HASHIN
q
Mashing technigue a mapping lange
Chunk o data ioto sOnllable luigg
a hahing
hahingunchian
Reyn
=1, )3,29,SL,629+
S)
( tobleno) 3
(22)> 22medo = 2
h(k)allsen
hcs)
h(68) 68modi5s 8 Hol unchorn.
Good Ha
h-(94)- 92.0medio= Easg to Compehe
Seporce chainig
hK)= Rmad o)t1
m
2
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
Linea Roobing
fley olision no
S&
b(31)= 31 mod12=I
3
1239
h4)= 43mod2= ) collision
2
H(Ki)=h(+ mad m
(u)h3) (o\lisjan lo
V) h 14 mod s) alleion
2nd collisiOn
-ls m12.(3)
n(S,2=
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
Lneqx Pyobing
DATE
PAGE
oPen adduLMing
Sep-chaining
isea Rcbing Bzisang
clteist
Quadsahie Qebing Stonou luyteing
Qaule hahing
nQuadualie Psuohing
m
H(KÍY h(KH) nad
H(Ki) h(k41 modmltt Lty MLILTTN
Paeblem
(M)
h(32) 32 modI|s )0
h) 2 mool
il) Coll isio
Deuble Hahiag
Sernndanyhash
hosh lunchan
nci3)|, nodI=2
31
he) modil () colsian
b
Hl28,)= hl 221tlch(23) Mal/
collis
H(8,2) h(2)42:h(2 8)) mad)
lood
X= m-noo Keys
M
tabe Sige
Separok
Chavning
=60
GATE CS Doble
& IT Study Material
HOJhing
https://t.me/gatecsitstudymaterial
DATE
PAGE 36
|36
812 19
322
820
820
o6)= \obrmdi6=t
=
hlsoo) Soo medlo=
buckel
2 e
Sol 3L 26, 43,2734, 1246l, S&
3 21
2 lo
8)
daudle
Paoblem A
chen oudaloto anelame
The Re- haxh all Pomaicng
Rae
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
3L
Conside a
dable bosbing in Dhish ha paimaxy
=
Hauh anshiomh) k mad
23. and Secodoxy
Nol hah nhalk)= Jt(K mod 19) aune that 1ab\e Sig
in the
mme23
helK) ltRmod (9
2141mad 23
I(mod o) Some
(3 Same euen
no po
lh joo lsbcollsioM
table
suroigg simple unilanm hashirg
ing chainig.
Ohat s ho puckalty that the st 3 Jot
unylled alle ist InAenhon
(99X 38X92)/o
s
0)
29
loos
Considen a 9
bohtable uoth sloth The
hon
NOduedhe
Chaining koy S,28,19,(S,2o, 13,12,)21o
The maX ayeag
mio chain lenghy
ropuhuel
3,363
h(20) 2% mod
42 tlt2tl
A
hash
haab Table c
o longth o w, apen addawing
dinco pacbing atea Sx8)
Hhe
hoh oble,
to'ble Shoun l gu
Lwhich one al tha allang
chsicey ogiuay
poxlale code
23
haue bea iased in bahle9 34
uG92,3S2 2333 S2
6
Ru,42,23,S2,33, 46
Sme
4b,34Z,93,S2 32
U2,uG, 33,23 34s2
tOM Gal Natch
prsbing
hoh able
s2
34
23 alua lat
Cauidaa hoh Table a, Sige ll Hhat lneg apén addxaMing nith incax