0% found this document useful (0 votes)
21 views151 pages

Data Structures

Uploaded by

RITU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views151 pages

Data Structures

Uploaded by

RITU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 151

INDEX

Name unst.Measspaa....R.l No...


Class ..Campab.SsAnCR.BIech.Sec..
Subject: .....s:A..
School /College: ..Physics...cJalloh..e
wo)

S.No. Date Particulars Page No. Signature

Chapkenhl 2legCanvension, Flou chauttand t to


Introdehion to Psueda Code, and Program
dcta Stlchne Oaha Shruthune, ineax and too3
Noninean dota Shruune

Aboay Fna(or xau major, spanie


matix LTM, UT, Tai

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.

o Hanoi 4bbenacci Soie

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
S.No. Date Particulars Page No. Signature

Chaples aloalszy Tee, TreeLeuoOolo4.Binay 86 Jo los


ree, Hul Einay Toel

ast orde, Complae Binsag

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

Teinigit, Gncoun Rabing


HAstINT Quadialic lrchin
Dauble ,
has hing Sepaoale
chaising

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

Coder Asimy

Aaigoaont

Conseat decima to kinasiae -

2198
231
292o
2
46 o 2121
223 232
24 2
22 2

(moo1),

Ix240¥21x2
=

- 128+ 32+4
JSS
Corwat deinal to ocal

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

4
33928 Š12433
3155
89 3 813
(s)
Q314)R333)
Conuent octal to deima

842+8°41
32

Consed cdonal to heado ismal


l6lg4s 1B

GS2

Conent hesadoimal ta duimal.


49
6449

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

31 AE2E

3479

Dayo
lechte no –09 Fouchat and kuedo Qoala

Sumo Tawo NunkoeHÀ


(Bucalo Code
Cincle
Read a,b
Read 4
ond b
fetialol
Recangle Prigt Ana
Haty=
atb

end
Subhrac hoo unmpe
shant

-Paxolldogrurn Any
Ar
Read
ab ab

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE TU

Read ab

Read
2

Point
L Hug

end
Find Cube a num be
Read

Read

RroctA \Qube- nxn*n

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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

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

Sautt Qi ime noou hn 2 hco prm&no


A or Rhud ye - Poime
-diuid
Rad n

hot Ceto n-t )


du-2

GATE CS & IT Study Material


imo
S2 https://t.me/gatecsitstudymaterial
DATE
VI
PAGE

Wite ou.
Hdd digi
Cout
Clam Aolhn 6

nom)
246= 9

int addDygis int


mum:
Iohile n>9) humlo

ohile lo6S
m=o)

Hhin
Lenp ye0H

cloa salhon
yeharn o toy (ot L9)
ínt ísleapl int )

olhe
i

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE_
PAGEQN
Hem

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

= NAnAN MA, NAM =MAM


6 Rillindhone (&x NA
121-I21
121 121- x, Ront tihoRx
Not Pallhodome lo32
Retae
Aclwhicn
lan
Palblic 6

boolislinduonel inb) JXiot323


Q3ot-23

(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)

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
2alujes23
DATE
PAGE OL

Ilata Suuucluote and Riacgzamming

Quganige data in auch we


nanipulate,
uetreie Can exhatt inlgxnaahesn
rom data liienty
Atoxe data

AroAe Hhat dataiohich


ho
Ahat going Accey it
o
qcing
Kind Ruipoe
IMata Strchune

ineox data tuchiro Non line a doto Nauctue


e an
It poible lhet
ahmost 2
neigblod lehment hauenore
Hhan2neighbous
-addeelaed
que tee
Bino
Gokedlit cede. fee
9 Combined Rigaiy Seatch
Shak que.
Hea
HVL-
te
Algpaithna

Collachen o Simlai hype

Trdor Atak ram. Reatticaly


lements Atoed One

Rela koe addowing


GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE O9

Random a(LOs qces he olement in Contant ime


(ahe Faiendlynes
Gue
mHhytesbase aàdyay tbA)= locoiot ALo
AE21
A31

\00

Houo mnany
lemend

ySoe each lernent hak

Memoy altaady \iled belore


AL]= 2x byte

o
indey to S

lo24

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
Thecosiehcaly neggive inlex axe possible.
DATE
O3
PAGE

Index can Akat om ay Mumba4.

4 dleent last- lisst+L


L
5-(-5)
touwest index leoqesh index
=l element

-S-u-2 -2 -I

Hotn.man alament alaad illed be,ore H= t


inde x
-5 too= o-[-s)
o4S1= b olement

ted balore AL]= 6*4o Qybyk


Memcalogdy

2bute Baueoddoy (BA)= \o00


A-20- oLh=

Houo man dignde alxoady liled beloxe s]=


o
index -20 -4

=
add (aEs]) lo00t 30= loRo Ans

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE

PAGEOY
O

Chapla2 20 Array
Rouo coise Store olurMn Wse

Rouo-me(o
stoe
alomnmer
-order

HOLO LLgih iadey

No d alemenet in cuy wilh index o = 3


c olement in otoLO
No aith index
ou, he I= 3

HYEue4 noo alemen=35 noo tolan

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

add ag4) loo44e


int alul[s)
CotuDnn 1
3
O( 2

coith, indo2 inder


inderstoca
many MoO aarody Gilled belor

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE O

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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE
OY

925ye
=
adilatJC)> looo+ 92 log2
2
-7-6-5-3-2-1123456
Que a[-s...s)4.. -
Kelemen
-3

Hoo many ind


ed
es-7o 2

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

Sige adh byles.

23
int a1C3IEMT
2-1 ayay2
to

||Tb

Eueng indax in thjs


index in Hhis.

dimena ion bperN di'menensNCM Coplo,Prt

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

1nd ex illed inder iled ndexled


-l
-Sto -l3o
1--s)4=-3)+| =-l-(-s)+|

lenernt

element
alement

3Tokal clemer adsoad, flled SkIEIARAtS


23 elemeht

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE JO

ndeX
24%*L element
element

-S to-1 -
lo to -sto 29
a-l-s)+{ =-(-10t of-3+2--s)+
elemer
S2*4*||

b Total clement aluea dy illed =Sx2 EAIl


4127kltuK
Ao61 element

19122

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

20 na CalumnmaisY-de
2
902

Col oithindexe Qluoith index1 cloithindex 2.

a
Int l3If4T

BA=Oo0
Wc4Byfe
Col uoith indes
Col uoith
inde

II Houomany calumn olataday (illed belane


3
with col index

2-ot3

-l-0|=2.

3 elermen.
ql31Lnyindoxvep

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGEI9

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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE L

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

921 Q22 431 432

atT LsX ot
Passible bcz LTN U quaze mabmix>

qu2

a21922

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

add

nang oithin Raooithindexy


HOL 4 olement oehrent led balore

to
2 alenen
3-\4
elomant
Tahal=
ft2elomany olhadg
t- dements -8
Gilled

qdd (ay2) ooo4 32= lo32

()

index 1 to i-l beloreAi

index 1
toi- i-itl
2 eernent

Assore

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

Not leasn Camula

31
Gue
add
S.sE...
Ai,-2)
al aleady
-5 to D
lllea/
clancnt alboadyt

-3--)t)
=

-2don = ent 5element


26 element
Takal deent alsaad,: illed
24S=
269= 52 Byle
2
add cAr,-)= loo0 tS= los

LIM in CMD notado


any

olthin
3l.
lement aaeody
=. e
emen
F5-3-2lenen
Roc-col
2232)9ve 952433ussu4ry9ss

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE C
PAGE

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|

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

(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

Ledne No= ng (28]nl2022)

X
X

addl H(BI
auadyied

22elenenk
=
2elamnt
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE IA

Iotal= 2g+2 clenont 24 edeneht


nogy

Ugen buiangula Medsax


Dppen friangula, maiA cs Squaa mahnix.

3.

izaia
Roo ma
osd4
2

ohot index
(s 3ielemdlrest
Bi
ed
=20 a34

=9 leet sentey
-
row

Total- lo olemes

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
enly valid hor ohen index sill sree DATE
PAGE

byenaal rnula.
TM n RMo

2
- 432

olem dlreodG1 fai)


belp aii
t)

Tekal aloment alroad illed= 2

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.

Tnsehien doleen oo erenlie

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE 2 9

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

Revele ohile Couo high)

Boaplatio],nhighl)
loLott'
Repe

6
Do20 3p/4o So
5high
bo

Sosp(Aibu], ALhg)
hig h

2 GATE CS & IT Study Material


Dlou teustt high nig https://t.me/gatecsitstudymaterial
DATE y
PAGE

Sonp Calosl,agh)

inttou), int high


Yoidateuexeint an1,

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

eiond langet clament in gyho


laxqt and
Travense
t Can e
doiti one
Travuyg
tosli=0:ien;í)
x) 4'4larrimar2
4aizn9a

no
May hl
toe knou maxrsNA2

Sohei
hen

nith a olemena I he

bave
eoch

no elanent alaady{iled o
to6

Nnoay aleady

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE Q6

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)

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
BATE Z
PAGK

Total elermsrd in oe04


310424 Ary

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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE-)
PAGE

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

louen ngul 20 0uan1(s1 usith


Conidna
louea tiangula Sqang maha

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

Nemosy aloady llod 323+ U= l292 Kyte


9292Ang

So
Hal
colk

biled -8 to al-6)()
-t-(-8)1- -7t8t ColRow
20

>31elamen

addlan 61)= lo0o+64

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE 39
-y-32-0I23
alanent aleady
led
-
-)

42 Bye 3

Soo t= S12

Lthout ing diggram


Naaleol 4illsd.
olhin tal inde-hi4fo

-2444(ls loman
Tokol

lauben taiangulon mahia. ind ho addnod o

2
KX

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
S8
PAGE

Oihin col index


lan alhusdylea
-9elonont
-2 +3= )
= elomon
Tohal
lo

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE

Sell oalanhial
Sunnd
Stue
Ranhka
PAGE

9 20

P
3000 Ptr
Suct
Pan kay
Typevor
Yoid main )) SL
Sp

sut Rnkaj S,s2,S3

Yanka ape vaiable

r Ptr
4S S S
Sg

Linlred >
List
Linked iat linean oat
ahich Collechan o
eonent,
Caled ohich node
Conlain 2 pat
data

inean daka stxucuHe

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

detyshuchut euye contptounte


PAGE
dymarmic
|toy
Uhinghuchue
How ha inplernah) inked i,t>
Gadok
Moid Inaoat (1nt ke)
Shuuct Nede
dnt datay
Sturt Nede *mext. : S dala (o
Vor

Racbler
Maid hain)
maloc help
Nede

Rir-maleclsp lliat))

Shruct uode

Qtxs malloc Sige (Shc usda))

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

Poinka to 0eLond node.


nd

Hou) fo Qcces net pode 9

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 Lee no=02 (gglul 2o23)


ink
data nk, data link date
da inkdata
nk
200O+ 203ooO
Jooo 200

START =
lo00 Hxsk Nodo addaM

Loith 2memb)
START data

$TART9 Unk

and node Poinea to q gnd nodo

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

Gilsena inked Caunt noo


ist the nodo
in Ain Gnksl

le
tt )

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE yo

jnt countnodel
rcgarn int count =o

ohile ( QtaNoLL)
Counttt)
Rir Phr ink

xohun count

lat nedo
Giuen a iaked onk ha dota
ho

ectot data ink dota Unt


looo Boco
300
|o00

r
= True true
loniletolink wUL)

Print Phdaq
his
nNuu)
stat ededata hile(hrink

hen
lat
node exit:

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
1STAAT =NULL) START Unke=nyoLL)
oOLL-
nkror DATE
T
PAGE

Noid Rninlay)

ISTART== NOLL wanado

Uhilel h
linkl= NOLLY
loiat(y.d todato)

nt ierond laut Nodo data


Lioen q
Iaied ist,
Cayeg START
Second lost ade
So do not nahig
START
Unk
no Aecond
ot Nod

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

Pl", Phr data)

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE 9

LSSTART

rr

Yeid Seandh lint Koy)

surt NodoetreSTART
ohile(phrlULL)

i5 Letr daty key)

Phr= Phrntk

a a code to
Guen inke itik puin akani
STAAT

2 3
START

op 1 2 GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE o
PAGE

otrink=doL)

LecHune noo3 (ealhlg)


LosenHon:
Memoy- all ocale

Pkst= maoc (sige ol


(seutt node))
Tnsat data) keyig his neu
Dode
=
ptrdata key

wbexe to phce hes node


START
Gnk data
dala Gnk datg
lo2oo 20 Soco

Tnseakon ad Begia
bynd
Joo ac Posiio

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
u
PAGE

START becone Sigly Gnked lis


ale msent

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

Pty- nalloc (Sip c(Staud Neda)


NULLL

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

¥S tart r= mallaSped (Strud ed)


No

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
Dynamic memey Thtough o
ut
qlocohon Scope
Pooaram DATE
PAGE

End Jhseafian at Dast

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

nsuni hy Teaveye tat Nodo


T

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

emp = Ptrnk temp;


data
key
=
Hemp> (ink NUL
i(START== NOL)
START= temp

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

anp malloelsizt (steut Neda))


teno data X,

=
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

int aekAdle (wode head)

Stxut Nodo "sla, *uf


Slauo =head
=
fast head

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

START must Qoint ohd Node)

Noid
STARTNoL

Qtr= TART
ond ode
START= STARTS Next deres

STGRI

STARI

ioNULL
Fee

Coe2
my nked lit
Pals

(STA RI =NDLL)

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

(START-> Dext
oAe

wbhile hr> next


>
nextl= noL

Ondey.
Biaking (isked Oat in Rewese

Oinked
it aal Reueae

Rastaing fexible
hen
weye

Prev urent

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE So

Sbaud Not otevedtut (Slsyud Nodo'hea).

Siuc Node ren neX


>next NUL)
ChtadsNuuhead
Mcun head

ÜuuH head:

head

Slass Sloao nexti


here
Go inked liut

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

Aiuen 9 inhked int gad hene ntoaealion

head

nerdL211
Peint

wohile cphri

ptr =
healn

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
S9
PAGE

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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
scending lnotejy Ga(2518
Nen deoes sing -,,s,s (Ninuy otet DATEo
PAGE
S2
duplicate

daq ee h> dafa)


Dat 0esta

qsa>nex:

ole

lechne No - 06

The Yallauoig C uncian take a Singly linked Qit


Vay an yqument

((esdat= P net >daha) 3$ 3(Pnext))


and

empta aa
excHe one elemen
he lis is un oeaauing r
AO)ed in

Toue GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE
S

20X
pdata neahdaL
P=null Not Pnet= NuL Not

olollo<sQo).

Noo &inglenoolQ

Ih Lot cae he numbex


heded to deah a dgaly

a
singly inkod y
SAeVeNAe
Spate 9 itin
Contant mamog

Oimked
LnaVaxioklg

m
elomerd into an
nainkaing in

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE S

14243 -4(h4)

Conxico Hhe CcoolQ quen


0men belous
Yoid join nodo"*m, nodo n)
nodo *p-n:
hen donenir

psnext lat node


D>next: m

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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE S

ReAuiang he elornent 2A34ss6


Noid cteAHAnge Stw f
Shuct
ink \erap
yode
it itnext

Vae

ypes o linhted isk

SinglyCinked dait

Douy
Cixculon
Heade
linked
Unked,
it
ut

Loubly liniked Out

hed
3e0oo/N

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE SL

Sbauct Nodo
Travyat
nt data
Saucd Nosde
net

Staurt
SUuc Ndo jemp= malbc

demp data= key


kmp neyt= heo
npreN NULL
head hels emp
head emp.

Cixculax linked int

Traueuo) in CLL

i (heads=Noll) eun
do

(ohile (ehl= head);


Head liaked iat
Con
Contain
Some soeie
Headnhd
Inomaior

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE

PAGE

Shsk and Qheue

ddining slota shachue


Thexe aays to

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

civ)Rh ingehcon and dol:ion oL


ot one end collod ToP d shack

Statk ha) ho opra Hon


pUsh
Delehe
poR

Folse
il stack is not

Truei Stak is tal


False
i sak is hot GATE CS & IT Study Material
ull https://t.me/gatecsitstudymaterial
DATE
PAGE
Sa

Top elemtnt adde


most iec enke
o
Satk numbe

Tnihtally toSGtt ((o) insoat(eo)


20 Tof

ToR

ToP>

-detete

Hpolicaion al sack
Recussion Fupcion
oy
Taiern ol
Hano Postlix evaluo han
Kalanted Paxan thesu checkinr
Tnlix to Prehix

The Raspsse a To to pestponcd deis ions


sk dehy

Tmplenert Stack using

int statk CsiZE];


O1 2 3 4 S
Top tagieyent index al
most CtEzenlky

added elstnant

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
(ahl) Callby Valge odual cugurpent No hanY
Souted calby Reloente Ouah(tsi,); PAGE

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

Noid lush ( STACK pS_„int x)


stul

Stak Roamutaon

guen
tohat could be Baible ode) ol Po ( stack perms

Element m=3 (L23)


Poible Rimitaion
= 9 34= (6

cadeno, in\exlion 2,3 youCana at any himt


o six only S aHe valid stack
out thee
Pouttautehian

slack ponukahan

leysnt =u (l23, ohich one of Khe


folloing Not-a va id

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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE 6)

Inathon gcon L213,9


pgrmuahan
Ho many yolid Stak

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

248 x46 12 X,7


mulhgly s diudo have Sanepritaiy
but withnaoiahu we paarm mulkgly

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

2 operand dired add in ans hen Ryhioto


Pstlix 2 3 Stak

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
G
PAGE

oferato

(e inbe

Vetiv
=
2.34Xt

inl a4byc

S inyix 2t(3 X4-6/9


Rostlix2g4X62-+
Inli (atb) cld-e egh X

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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

no 203
lehe
Houw to evahate posX
Voltlia eueluahon
uluchon
Stackh

inja= 2t3*S Stsek


Sx3
Poslix
oesa = (Any

i Pop 1stelement > A

2nd elament lyam


B Ang A.

hen
Puh reult onto Statk

235Xt S, 3

+5IS 2

STack Tof= Any13

inlj 2439-6/g
a

2 Hpux-62
Postbix 934xt 62]

4,3 S3X4= 12Puh

12.2 12 \HPyh
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE

Cii)/: 2,6 =

(u) 3,4= (4-3 11 Any.

(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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

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

t may pop ol he top chonnck at ahy


bt
hime Luhich one Yhe olloolgg Stig annoj

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+

ahile (lc=golchan)= Eop)f


S
elsue
i (=4)lce ))
Thi is ponki code
+
So S26339 +*

lo 3
Hag
yoor()9
Caictf(clopO;2

The atibu ah hoe onitnahe apeatís Some PL

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

Oleatox recodono Assauahoahy


Ari
Migh
Right
led
3)
A

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

CAQOlon ho baloncod poAanht


Stoee

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)

Void To int n, chaN SeMCe, chax Dat, chaxy Auk

painti[° c2CSoLirce, Qat


ToHC n-, Sauxte, Aur, Deyf)'

int main(J

ToH 0,AR:

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

Lectue No04 s/eb/2o24


umben a unchionh calla An ToH(n)

ToH(3)
ToH(2)

=
Int no o uncho all

JoH( m)

ToH (n-)

Tonn-2) Touln-) M
Ton(n-2)
Toth-)rN

ToH(2) M Ton(^) JoH(2) M


Ton(z)
A

N
Ton(i) Tonl) ToM()
Thl)
(G ntunl
4Auncion al =
+e+24--+ Sn= a()
2-|

Hboonacci Sexieh2
ix

Fib(m) Fhln-) Ebln-2)

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

Fb (o)
Fb()=
hbl2)= 2
Hb (3)
=
Fhíg) A Kh(il= ltl=
jnt

1b(8)

Hb13)

No o funchon als in b/)


CallS

Ribl 1
ibl)
Fbl3) 613)-S

Let
Fblm) Cal

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

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

O,0,1,2, 4,t, 12)


GATE CS & IT Study Material
2
https://t.me/gatecsitstudymaterial
DATE
PAGE

Wue Numbea o lunchon Calla inisked bol

ploro. in hbln).

Altx (ne0 {unchon call invakakan rstatbior


Gill take place

Qnene
ineo dao stuchne
Erst io hcst ouh

Insetion ea
Fyont

Simple Sueua

2 3 4 S ist Raasi

Font Inder (on which an darnand com be delod

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
Insenmon Rea Chang hogy
DÁTE
PAGE

tohen we ingett t eloment


o23o 2

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

elseiC Frant :1)


Renx= ront
= o
o
else
Reat t

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

Deauene
Con not deler
Yront
Dequaut ini 4emp'
int ()
aleol

Save etomen
Ront+t
=
elaneni Rern
Front Reo

ese

Citulo eue

Reart| 2o2 Sront

Thgat (Go= Snaquae(Go)

Vous Rearo

Reay

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

CayeT R |to 203a )40


Toihal Frenl Rear
InseatG9)
inseN (20) Tront=0 Rar:Sige-l
Lnscal (30) 2 1hen ove
loue
Inseat (so
nseat Qucue is(ull louerou)
CaneT
inuhaly
rott
Enqueueíe)
Enquueno)
nguane(30) 2

degute 9
yeue is att
nquouolao)
Reay front -1
Enqutue CGo)
2
2
6070|o) 4oso
3
o2
Qeuer is

(Front'=: (Raxt)7- SIZE

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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

qulomad an slack Sand queuad

foß an- elomorl from


dbqusu qn elomNt hrom
S

doguo an dlomon from Q

an aoman krom
V:o
Doe an olergen from S

STeck (s) sl8|9


S9|62

Tof Tof
The Tof elomenfo Sadk

ContonAg none. Tho


on OPoachonallau On hore

Ihe ihqyaue Oppokn On oaqulkd to

an
yi addata storage GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE

Head Fnal State


Mead Inihl soae

Head Hed

Cnquoug
2\3
TB21T
82

S poQ

daquoue enauu(22) Ghayaug (32)

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

Visit ho Yght Sulshreo wing Neo ordeA


Uist lolt Subhee Neus -caden

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

S-26 Pot orle


Righ Root
Lf,
2-25
mea
Reveye lod
Gue
elomurt
the elomen
Head CO) nekun
he an Qmpy sack

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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

312 Tof

2,6
more ovo
9 tenahn (ineoing

ye
elem in gtatk
grd ienaon e

lor al t (n)etam ikaaho reguscc.


4yn-3,2INre
eahon
3,2
2n-2)F
nhehn2
N;h-n2--32

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
ATE&6
PAGE

loz)2029 (Sahuday
C'inocx5
Dinetoy shuctSte
(20)

Pae Tee
Sinsy SeNch Trte

B-Txee Rt Tree

a
)Node ' Each elemenk depleNent ky Ncde

Child: lo and g0 QHe hild lor node loe

Node ushich dine Hy abave


is anohea
Pantnt Nod
pauent a

Roct Only pade usithout an Pouent


Aadei
Node

ohld

(ea node

child)

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
Path

DATE
PAGE

the o
no' chld ol aa node

Hesght Heignt o aa Node


aaode i Yi
nodo x
he
to
ltngth
he
opathom
node
\al a aHoot node
tee heigt ol

Ievell Deph a a Node Lsuel a a Dadex ú he


a lxom soo Dode to
engh ah

()
the Hhe node, in ht alh

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

Soj and ao Siblings


o.

Roctndo Can pot baoe Sibling


Sibling

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/

L date Risht data


Sooo

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
Stytoole
Strutndo *\eht DATE

nt datay PAGE
9O

Stuct nNodo * Roat

kall Binatg Tieei

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

Jnkana) evay intnal node


node hos 2
child

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

has exaty
2

To tal noo
eoch inkana
hoontoono)
Cbild
o 3
nainkanal neda

eyeng incanal nods


R-a tee A
free in uhih
he no
Tree (raot)
k t
Total nede
TX
Each inena
hade ha K-child

(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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
y
Node, L
Right
3 6 DATE
PAGE

Level onde Dephoxd ex

Roct
ínozdon

Right Rost

|e,213,S3,8

Bae orde Trauenbo


Visit Qasceg tho

Txasee Risnko Rost nado


in Pre orde

Rse
oden3 A80ECE,GI
Yaid Qacorden strudt alode pts
=NULL)

Riaht("APhr> daka)

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

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

Subtzee ol noot nodo in otden


Root
Rracesvisit Nod

Post oxder
oEEBHnCA
Vaid Qostoad on (Staud Nodot
Ph)

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

(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

Sor eu StrachNe anly Ong bingy ree

shacheo
QueNo oh binag toees possible with ostosle sc0A

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

Elactys ne guer
gjuen dxauea, al (irsinfletl
mdongth

No

wimbe

c
lot

(uith a awen Re and Qost


orde, no binauy

A)
Sol Re

Thozde AB
X

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
CRordo
DATE
\no
Tsee
1( PAGE
93
pecotdes nlenath)

Yostocdea nlag
treeaim gieo
20

ue

IalReb) 2624

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

Yhen make bree

Root

Camplek Binag Tee


A
Conplote Rinasy Tote is a
LwhichiR Second
icdo at lat Qosel a
illed om
to
at
-2

Riant oisiy

I, Thys Connlele Rinay Tree

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

lg ssT isq tinony tree in ahich Qyea bede

Sabtaee o a

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE to)

than X.

RTH)

Aue
Hhe Somo 6den
o Roo|
Insent
Inseat 20

(6)

Casruct BST hy ineahgg ollocoin Key ín Sanne ade,

o
isealhng

inseahag

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE O

Drdan not ven


(1
(to
(
4e,39,2o
200, 30
20 80
30, 10, 20
SO204lo (3

Co Both
Boh Tree
Tree ase am
=SBST
nt
kegs

lo2,1t130
Yseosden lo0,99,8o0,9r,42
99,i0 o2,)3o

Hnd Post oadon Traueual


ho
Sol

orde GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

130
130

(too

go Bo1299,990, lo2, I9,0,(o,le2

m
ith nada
q
bimy hree
sthe
and alo nIroy ag
uen oo man

lo, 2,Si,&
incrconing ore

Seach ina BST


ReyO
sioompsvision
(46

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)

a 9odo haug 2-childl


DRarent

((00

(92

re 7o (\ea)
se need fo sdenhly he 'axet einhea
Seach

hake
(160)
Poine

(20

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE
O
(rlozl2024

Delehon o node one chid

Delele )

(20

(6) deloe to and conred 6o

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

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

qnd
min keyin
Replace 9o boih
Righ Subbec (92)

(92

(lo

height babned AVL Tie


AUL-Tree

o a bode am
L Balaning lgtox

fador
A tree AVL Tree

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
L

DATE O
PAGE

e Canhud an

insehág(30) () -2
RaR Rokahm Reguicd

This is Balane Avc Ten

Tosent Roys 5e, 20, 60,o, &ls, 32,46, 38


inget 2060

10SUt &

t LLRoaho
(20 (fo

insent iS
1R Rolaho1

Angent Jnseat 3R
32h

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE O8

(20

R
((s
R

RPRolea

insent E

LR Rotoho

Inseat C
E0

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE

(e) (Oa
PAGE

RLRofot
(B

k
inseat

LR Roiahen

|o, 3o, 20
R

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE O
PAGE

Gues

)
t

Re

Inset LR

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE )

R 2

R
This is AvL
iee

-4

Min no s nsde in on AyL Tree o heighi hs

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE_
PAGE 9

hoda in.

height s

m(b- n(h)

nls)=n(s) 82

heigh

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
(6T Complh siny Iree

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

Constxuchiso ol heap be ingerhng key one


alkr anohtn
a guen od
in
Same Aode
Tnseato insutzo
at ()

isit maX heap


insentso Sua insen
fto
t 20

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
n Yn)
heght ol log
DATE
PAGE I[

(mlog hea

60

YEAP

n o
inseat in heapnith hode osn)
ee Repexen tah

Jinted it Repayanaion Daty Right

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

Quêngleal ndo 4 indexo


(20)S Sahs intkanc) \,2,3
alaa
hode
1 to

Hexpiby at So

indexle

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

Heqpby
2 (so)

index
20

toSo 6o uot0 oO
3

Hapiy algcaihrs

langzat

(argat Right

Scap A], n[lagutD)

2o2y
Lechne No08 8Feb)
Inde x
=
Dodo

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
I|
PAGE

(2)
One altor onolha.
xdon
Build -heap by Heap

2
(23 3o) 2

Ruitd Henp (A,n)

heapyt Heapity (Ain);


ndex 3

henpila
)

(o GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

(jo0

Nade.

3) (6o)

Niniom anong thele 3

Canbe
ind in in maxhtap bn

HINheo
A
o2o3o4 60

Had nin
in mhea o)
Hod ma
in m)n hop= DlD)

qeasdhing an alonant in a heap

delge álk, 6
dodeachO

fnode
deletkd
6

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
COngtont hm

Heapiy (A,,n) 2-oonadooo


(g2
n DATE
PAGE
|g

(o) (30o) (60

Delehion
Toseion ollogan)
Seach
o(L)
o(m)

Ae Hous many saax hap Can be possible


oith3

(19

#o nax heap
chaicedor
Root I (MaX
lo,20, 3ouo

Loith 2node heapolth


I Nade

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
k-ag >9-1-kK DATE
PAGE2o

LI(2ke4) Rermka 'lg20,jo

outd S5Sekiam

0,20
(uo)

1X6Cz
f2 X 2

3X3

=
T) Lx

Rght

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
Ck x
T(kjX T Cm-K-1)
Roct
selhng DATE
PAGE
t21
teabl fnorky
bxpHeaion Taee. hiyh

operand
togi
operato; intrn al nodes

qybt
travezya°
lost Ruisxit last)

Lieoatriaty

(eat

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGEL99

Poshix to expreMien Tee


Postlix 9

43X2t

SI3+bo90
Si36
6o00

243Xy
Reuge :
43X2t

6)

SI2

)(ec

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
uncey eperator
binay apoator
DATE
PAGE
|22

loa nay aperator


unazyzhiatf
opeaand

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

giuen se so that t Lecome a


BsT
A

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

19, 20,4oso,4o, go,96

lo 20 RT
Wever be TraveHed toj20,o NUeN

60 Ao, 8o, 90

Olg inocendingcada louvesec ony 8,5


indescendig

(1o,20,4o,so
Splace
Seletn uplace

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE 2

slo209y
6
Chaçter>
CuRARHS

San- line0 data Shuichue

ej= U2),3=(a13)

ualL(283),39,(134
Garagh Ropaeaena hion

Aljacent Mataix

Aaiacony
ethe

0hea'se
A

2
edge Hdag (i)
3

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

Lüpen dintrhed

Ghoph Sparse
penie

Nede

Adiaconcy ut
(

BFS (Breadth lirst Seoch)


(Oeph ixtt Seosh

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

Jheae con be mahy


9S6282 3 Such Jaavemal

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE

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

h(keay) |key) Mod m


93
68
=
h
(4) )4 modio cH
hcis)= l mocd
jo

(22)> 22medo = 2
h(k)allsen
hcs)
h(68) 68modi5s 8 Hol unchorn.
Good Ha
h-(94)- 92.0medio= Easg to Compehe

Csllission collision Reaclahdh Techniqug


Linta puobing

1) Quadeakic obing Hag funhon


Dausle hahing hr)= k mod m

Seporce chainig
hK)= Rmad o)t1
m
2
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE

Linea Roobing

fley olision no

Ney: 3l, 26 u3,2t, 24,uG) l,se, 3

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)

hs84 Mad12 S mod0) colsiovy2hd


NSB= hS&+2 mod 12 6o mod O

n(S,2=
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
Lneqx Pyobing

DATE
PAGE

Biny Cuteing Raobilen


Psoblerm Lohen
dilon kog
allíleto
Collišien Recukan Technique

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

R9,1432,2, 13,so 30,64,


M=
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
S

(M)
h(32) 32 modI|s )0
h) 2 mool
il) Coll isio

H(2,1)= (h+) med


i13 2
colisionno 3 modi)= 3
V) h03)= 3 mod s 2 collisien
H(3,1)= h3)+1) MedtL

H(B2)> hls)42) modl


M(13,3)= hlB) 4 22) Dodu
32
hls) 5o Med
I|
= 6
tolliscían
h a
3)
NID =
hl6[) 6l med
ll=b collisuon

Second cutcigo ecblem:

Reys hat Oe hahed to same memoty locahion


alltcayt olaos Sarneaclukn path beg d
o
uhich We
able uklige
table Sige eticicntly
qlmast So/. |xee Slos
Deo
olonents
GATE CS & IT Study Material
https://t.me/gatecsitstudymaterial
DATE
PAGE
)3g
Secondaty cuaeu roblem

hc2) 2 modil =2 Free


22
VID
(2) (hl2)+12) modn 33 Froe
S
|2
6

H(32)- (h3)+modi=G 8 Free


133 H24,3)-(blQ4)
+3*)oeln O ee

Deuble Hahiag

Sernndanyhash
hosh lunchan

Roy 21,2, St 28, 30, 21


3i,
be

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE|S

nci3)|, nodI=2
31
he) modil () colsian

b
Hl28,)= hl 221tlch(23) Mal/
collis
H(8,2) h(2)42:h(2 8)) mad)

H(20,3)= (h(s) t 3: h30)) mod ll

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

oo, 20o, )25, 621,8636,. lo6, Sao


Jo|6
)

812 19

322
820
820

o6)= \obrmdi6=t
=
hlsoo) Soo medlo=

buckel

Rey g,26i43,24, 34, 12, 46,lLy, Sg, 12

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

Gilen a hah obe T


unith 2t slak hat hare
elouaenh, Yha
2000

one tho tollsoia


Lonidh fash un on inheqh oill
Aistibee eay mast

I(mod o) Some
(3 Same euen
no po

GATE CS & IT Study Material


nlgrghttps://t.me/gatecsitstudymaterial
DATE
PAGE 8

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(2A)28 mod3) Qug: Suns obs

h(20) 2% mod
42 tlt2tl

(3,0,) GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial
DATE
PAGE439

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

Aho in inho ohich ho


lat decoTd i inealed
2
2

GATE CS & IT Study Material


https://t.me/gatecsitstudymaterial

You might also like