Data Structures!
Data Structures!
Dato. Stucthes
Data stuctune- Matthematical and model itehhelated doto
Containe
to store ter dota stt et elemerts hare ainewt
data paionities.
for iearcling
Quee
seauch tree
inded ist
HAVL Tree
Hasa Tole
H
HB Tre
H
gt Tree
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Syllabus
L'AYray
2. Linked List.
3- Queue
5. Tree
Best seloctien so
Data ttat
wput, utut
and wtermRdut veute
vsrfik ,Structure can bu cceed geuenated
minimw
ubiliytio)
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
2. Inseiem ;- adding
a
element u
data stuetne
beLetien - vemovmg eleet tron a
datoa
stutue
3. a
Seaneligi fnding elwt w a
data styuctwe
5 Sonting aoangg elenenta
de
6 bivg 2
data stctung sae type
Overflewi
Hhen tuten, wtieve possible.
This endity u
called oerlow
d to
Underei
Owpy an, wo
deltinisa posble
This Ceuditen is called ndenew9n
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Rtiziv 2r9vNT
ALaoithim )
measre spatoU
to
2
Ru Time complezty
measwhe,
putht
by te alaoHim
ey routl
Rate
Measwe hate at wth tu unte
w
Exanple
T(n) : nt2 nea
T(*): 5 quadriatic
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
ascendg Ordey
Complexites in NOl ofywye
of gouth Complexdy
Rate
Constat
w
log
Logani thuc
Linea
wlogn
Loganitawie ininea
&uadhiatie
uibielma
Enponeutial 2
Factorial 2parowsq
)
for( i'e n ; ibl; i:
Mt2j
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
A
symptotic Notation
Big
Previdee tabtest uppe bond
worst complexty
D(R)
2. Omegoa 2
ower bond
provides tyht est
best case Cdea)
-
3. Thta
pravi daa averag bond
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
o
Colleckie elenets
stored en locatin
Al eleet can
AU
elets e'wdies.
Dežinimg Longuag
Ex:- wt
ddnes aay Bae addreu (B)
Stuctu
Defining
De oay in Data
depuet ay oreypecti t
qeuenal atotim to
I+8-Jj :2NA
name
Exi A[2:15] Ls:18]
8
, , 2:6], »[-1s
|Size ot aay
s
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Locatien t lse)lo)
at Locatitu(AC1) Base t
elwnt W*TAB
Thavensimq in Aney-<r's
othh Nisiti Runtime
Allj Complexiy
Spacs
Ques
o
Conside a O9hat A|8:16]· Totad nudoen ends?
Ans:
B= \0D0
|D40
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
JL-5
Finding mi
mininmum eleet
=
meeded
No ot cowmpariens
min: A[8].
for (i:
Ltl, i<: Ugi t+)
fAL < min )
spoee,
L
Ruutie
mori
Max
Ruuvtime
>
4(A[] max)
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
2(n-1)
meeded
method, is used
to be doue.pa )
waxi mum
posible seletien ca gne' miium
2 compaisne
MetHod
ists
2. and
O Ceny Create pavu et 2
Compa ayooo elnets and
et tee pain
w
it sial
RT small
tist lange
Oþerotiau No
e compaie
Rrepa 2 uts
waimum
Total mo
3n -2
2
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Touhnament etandDivide
meto d bivide
and,tougen opproacla
eeded :
Rundine 9()
nd winiwm
nd wanem
Best atgon Ham to
o (n)
spaee ei)
MthodA
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Lineor seorch
t Linea-SeaelA], L8, U, tem)
Runtiwe o(n)
Netun L-lj
( bsth
Linear searc caun lbe
a
well wonted ).o
mwd Low +
A\mia])4.
Low wiatl;
vewn midj
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
2D Athay
colectien e4
2D Arroy In c-Lagug
<datatype >
A\31L4]
cotno=0,1, 2,3
LBib
UB: 2 :3
2D arsy dedaratieu 3
2
Aoo A DI
As
Ao
A
A3
2|Az0 A21/AagAs
OBi-LBi tlt
()
2D Arroy storoage
2/9 222 21
mn major ordeucng
2. Ceu r.r.. 210 219
200 202
Al A21 Ao: A
A2AosAg A23
|Aoo Ao Az Ao
-Istice
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Locatim (A
l
umn
Comn najo
or
dexing
Locatienl
a°lj]): 6+ w*j-La)*mi-ta)]
Lower
nonZero sthente, ()
o-
elennts tored
2
Ai Ar3 AA
A A
A3
3 4 5
A4 A2 A31A
A
Jos |Ar A3g
Ay Ay3 ryy
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
oeatien (At
2 2
- (-j)»
(il
.
Total
2
Az A31
32
200 202 206 22
29 220
No
elenet n
No
No
No
4
elt n=lji-]
n-j+2
Iotatb nets=
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
nlí-)- -j-2+)
nj-) -) (j-)
Locaten(aLJL) : B+ (j-)-j-2xXi:)
w*j)-ji)+ i-j
2.
Uppe Thiawguan
ZerD
No 2
An
AzA As A
Agt AA33
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Rouw
Rovo major or deing
: rO3 n2n
0wI, to
Totl
n-li-2)
n(i-) f-t 2+ ---..
- nli-) - (i-2)(t- 1)
2
JNo. eliets
=
cel (j-1) j-1
eleets row col to cel i4
hetore
Total no
e
elets
l+ 2+3+ --) 2
. Locahiem B+ w*jj-)2.
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
si-)
<br>
covebad.
eleete he wodiad)
deelared, caunot
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__21094
<br>
LINKED LTST
O
Linea data stu cwe
is maintained pauntun ( liuk)
Linear oYdey
odes.
O List cetae data
fields Elemint k.
Node cotae 22
nert
fist poivtn:
Linked List
NULL
struct node d petnter
3
NULL-S
ch data
struct node * link;
-; Rins2
Empey i'st Coditiem
Cenditi
Sngle No de
=: NULL)1
4l stat > inh
Nod
L+
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Thareraig
stauct
P: stat;
wbitelp]ew)
puint(p>dotay; CenpltoE
o
Finding oddne lat
stnict wode *p
Jiar p: start;
4stiettint Runte
Cowpluut
L
pnisninsh
alas lmear
"Seahing Akod tut.
Seanchig in tem)
,Secnelimg (stat,
styuct nod
p el
stat
.
wthie lpl= wl) Runt'ie
=
i4 (p-> data
Pi
rctwm N;
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
m
mhed Lst
In sertien
node *) malloc( siy of( stuctrnod)
struct node * n
w
>
Inserti
ndat: Ruustine
e4)
stat
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
urte
strut wode
(I}9 treelp);s
mo de t
9)
stuet Rvd'e
stant =
stat iwk j
free (p;
mode,
Delctien olat
wode *p,= Stout)UDERFLOO vetun
stuct == NULL)
trtte itl stat JULt)
totite t p->tink
P P
Rus
tetw freely
node
ine); Ruutme
free ( lot Cewplxty
a
'Deleten beee
wodi to
Strut linkl= loc)
wtailel p-> ind>
Rtme
P ink
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Lneed lwt
O To stoe polymomial
)Univaniate polyomial
vanialole
Coe Expoat
Node :
Stant
) Bivaiscte polyowal.
2 vaniable polyo wusl.
+7x+ay -=0
Node
Stant
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
st
<br>
Header List
wode called eeadeimod
©
headen wode contaus aumnmay iyoAMatm.
wode vstored boz tor wost
(
amd
and calubatg
tales (u) tii wntine
Not
5
Heade
stat) node- rJ}
head
Headen wat
Trarersi
rrcutan
Gyounde d
9(n)
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
gobaowlnsit
Linked it
Doubuy Linked List
.
Data
prev. next
Last
lat. (Last poutn is
waintawnd or
loackuwnd
fhai
Insetie at
struct dnode *p= stuct mode
mallocliyet (shut noda) );
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
guren wode
Insetion tn a
shuct dnode
P-> data
*p
itewj
tt dnodai) matloc(siye stuat diod).
Loc) Rutn
-
Loc-> net
pnext prev = Pi
Imeabew belore a
gien nod
ada
P-> data;
(stntfote));
stuct drode * (stuct dodi*) mallo(sheot
Ceplewy
lrtilel p> wext l=
NULL)
P: pneut;
n-> prev=P;
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
free (p);
e a
Deleten
e Runtne
loc -
preN;
oc ext prev =
be
>prev next
treel loe)
(1
at tee end
Last mode
Deletio heady
stret duo de *pz
Ruute
Cownpinty
pr
pretink
NULLj
next
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
QUEUE
OA
near data stuctue wlicl
w
wetien can be
Linea qe
(Yeor: N-1) Overte (vont
4
o22 reanz
(uditen
4(4rantrnas)
Condulu
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Applicotiens ef qe
hoguets swngle shaned resrce he
O Sewing
CPU tash selhadig
dusk sehedl
b{w 2
IO, et.
paceses
to hold people.
Pogowed
Double Ended Queue
seutien deletieu
Que wlieh
tom loeth ends.
<Deletion
Gutput Resticted Qutput hestuitd t
eu
Deuble Ended standand ud | Aont
fee
Qusue
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Quene
Paioty5 3
bInsetn - n
uch
a
Inietieng
Iyet eleret Iwed element ot
taat elewents ae 0)
srden
-eas
to rean. belatien
Find tee eleent
Deleon 9(n) wtth
Delct tee ud datte it.
90)
elenend)
to
mplement stack
stack and
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
tastnway su
Elemnets be acceed
piontg)
Oadd
caw be iwpleentd
(oijaba alyoaln).
elmut)
wsed real tie systwe
vetreies'igest pionity elt
(bcoz quickly
delotel)
Lmpleeutatin Lwsetl)
Seancu
Binay
ree (6S1)
ol)
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
STAGK
O A
limea data tuctue
w
whichi wenten aud
eltis beth
top the te
a
O LIFO Last
In Grst ut) tinni 4o
uihed ust
Lt eleet
wiented:
u =
Insentiev stack PuSH
Delctie stace POP
Stock Pemutations
sequemee elemet etained
elotain
elweuts
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
element Catala
wumber
o
valid
No e stach pex
wutatieue
poslble
No
pemutatâne
Exawsple
2 3
3 2
valid
13 L3 4
z 5
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
fengormed
sfach
PusH15)
-
PUSH(t8).
- POP Sequee
- PUSH(45) 1815, 15, |5, 15
-fesHS)
- Pop
-Pop.
POP
-l5
-PusHIS)
-
poP.
Multiple Stacks
MethodL
Dne stadieonot
be use the spee
Stacu 2 stack
<-staclel
wtiich loads to
Suitiathy Impoperbi
topl -i ubligatiam
stack spae
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Mehod2
2 stacks stant fom oppose eds tae
stackl -stack 2
Subally,stacks
tapi= -1
Oveilow:
tepl== tep2-)
botz
tep2 = tepl+)
lhatto
Betteu space utilizatv
miiimw
to a stac
Tuso
(2)
lht he minim
implemut
egied n
Tuoo
Ay (2)
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
2 qyuees ne guired.
PUSH
Insert
POP
Staces
ENQUEUE -
Pus
elenet to sI.
S2 Aud pop om
4om J1 to
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
ond 2
<y < 2
and 2 m
D.
DELETION
Total wo'
M+W= 2n Tötal
4 PusH poP
s2 NSEIO NA
DELETION
2m
<br>
Applications ot sto.ck
Expressiem Evauatiu
lo(Recwrn -las)+.c)
-((ses)es)
1-Expressiêv, ealwatie Rui's
2ra retix (+ab) oi'sh Notatien
ObeyatoY Preced
ence
Lett
Parethess()
Eponet
t(ssca) -r) Muttp Let
Dþerators
Unau
Cowersiom C3dqqA
to Pretix and Post Poctix
Inte
Lnix
Režn
(2+(3*5)) -! (2+(3*5) -I
2+3*5-l
: (2+{*35) -1 -(2+(35))-1
(2% B35) -235 *+)-)
235 *+|
-2237g
-b -b
Z.
lagl
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
(a+ B) * (C- D)
/F- X*Y jzat d
reix
(A+8) * (e-D) /F*Yjz
(**Y) |z
*co) /F
(tAB)
o1*tAB- cD)]F-/*XYZ)
-
((*+ Ab- cDE) - (/*X1z)
- 3XeyhtdsA
,*F/)-(XY*zI)
-
ABt CD-*F|XY*Z
AB+
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Post4ix to Infix
e
da'e
atb*C
atb*c- ale*f
Pretx to Dnix
Revenie
tu pretx and
pretx selre y'postt mehod
+-62 *374 aA
473* 2^6 -+
2
7*3 Ts3+ 2
7)12|hx342-6
2NS*)
Aus:
z*3)t2-6 4+(7x3)2-t
(T*3)2-6
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
to prefix post
Conrent the expreSSL ad
-
atb *c dae^f
Pretix coY
a+ (bx-(aa(enf)
A
a+(*bc) - (^ane) A
(taxbc) - (^a^e4)
1((-)5-4 a* be ^dnet
Postfix expyessiew
a+ (b *) -(anea)
a+(be*)
(abc*t) deta).
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
to
Convert wi
D
ha- B #
A
B
(c-) B*(c-D)
A
A TA+ B
Aus
|* Iutix
A+8* (c-D) expresiem
2.
32=q 45
5 5T5* 9302
2 2
22+ S= 47 64747-6=4
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Aonithn:
Add parenthesu ) ate end of
wntil )) is encotered
Scam P trom ut to aiglt
counteedy pUSH t
uto stack.
iseuceutered,
i: Pep 2 ewent fom stn
op a aund put e pust
tvaluott lb
heult eto stacl.
3o3o 61=5
JarsilDtlbt515 15
4207
3
25 3* 3 =75 75
5
I5 315
375
30
8
-
340 t340
=
382
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
5
3
P'hetix Eauotion
Agoitl: at ttae d
Add niglt pareutheis
0
:
wti (uesiterel to
PusH
eucswtered,
Stack.
stack
2
elements fom
i.Evaluat a
teu
euto stock
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
lostix evaluaten
Prehie evalaten
Ques
*
623 4 M2u9 rttun
t 5
Au 5
Ques
/3* 4 + 4 + 5 3
2
12
3/103
36
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Ques mto
Convent
evaate - q
(2+4)*(8-3) / 4 * 2/3
w
= 2+1+2+1+|+1+|+ 2+)+!+2
POSH epertiene
No
4
No- ef POP eperetze
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
2 Recur siov
tunctiebrealls it ig
called vecsien
o")
Recursi
AC)4
tun(tunn)
B)
tunc)
functiu
statewdeut
Activation Record
Wheerer a tunctio call, act' vatkon
(necovd nd puushed'eto tu stack
cctiratien record
cal
is deletad fvom stach
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Que
I 23 4
priag("d,
PL3)
tuuti)
(uto) PL)
Ques
Head (iut ) Readl3)
void
Head2) Headl)
Head (u-);
prandt ("d, ); Headl) Hecdl) HesdlyPe
Head(x- );
L
L
hendls); 12L 3121
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
X(5)
C)+
5
x() + 4
retunn i) -t 2x(3)+
3 xU
else
retun x(w-1) + X(N-3)+)>
Bues
ut X( ut N)
X\5)=7
etuw X(7)7
else
veum ( x(»-)+ x(»-3)+)'xí:) +
x(4)
+ 1
Ftbo
n
acci Series
=
fib(n)
fioln-) +
fblw-z)
2
fiol3)
No additiens tor - 2
"tol3)
:5
voiatioue calls
+
fowmctin call
iwwocations 2* fb(n+1) -L
No B
tor
to be tb[n+)'-'
additions dete
No
6.
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Tower e Hano
DFFSET END
START
ti
cisc canst
plaucd VeY Saller
be
TDH(m, Stant, Aux, Eud)
4(w>0)
TDH
(n, Stawt End, Aux)
More L
disk tyom Staut to End.
(t
Rnte
n
For
dies
movemnts, =, -
dist
ntl
call! 2
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
203
GATE
that iste etn vale
value otp wwityed to 5 betore
te call?
Mote
that t trt paametn i
reton (x,c) *;
5)
lrt
tun(6, 4) *
* x -
fu(7,3)
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
(ousice toe
static ut
i4 (uc-o) retunnl;
ts)
Y=ø5
t(5)
Sors 3) +2
(T) is base
t(2)+5-! ll+5-1b
fU)+5 6+5= I
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
L-22
TREE
Non uear iinarciial dota sttune tthat cest
(onnected
leveld
Tree
Tenmiogt
leel
ORoot
Node
O Child Intenl
Paeut
leyel
nemoe
* Depta a node: ta leel
-
Hamdshaing LemMa
N=I+L
()
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
ues sho
-o4
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
al b, e(e (min)
(m)
Huigat e Tree
at ttue patlh 4rom tee oot to tee
No edqei
in
toathest leoy wode.
: (M4)s)A
H(Tree) with
H[Tree) max level uoe
a nod
i3 associated with
* Deph with tie te M)
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Binahy Aee
has warimuni 2
cilden
A
tree
Linked Refreeutndnsn i
Lett
key
Child
g
struet BTmoda
stut BTode*Lcild
Shruct BTnode*Rcild,
ab Root
petesh3
b
e
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
a
Let Nlode ?
Hous to deteet 992
4(t ehild
= NULL 22 t> Rchd =
-NUL)
NULL
t peue b wode
2
modes clidew
&ues
o: wodes
In thee the 2 23
and tree?
wodes
Total
No: wodes (): t| 23t| 24
No tutinul ||+23 34
Total o
uode: 24f 34 : 58
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
tuat can be
tee taat i ca be s
2n Cw
Censt cted wth dtimet heys
moe
Maimum ad minu a
thee at
level woer L: waxinn
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
20be
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Thuee Trovehsal
stlshroto)
Preorder finctiowq
void Preorder struct BTNode *t)
4(t)1
(1-d", tee t-datn),
printt
Preovdei(t lttid );
Rreordey
(tRgit clia );
thsrds
Inordéx Functien
Void Inorder styuct BTNode #t)
i4(e)4
Thorder (t >lethid);
pit (6 "dy te tdat);
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Postorder Fumctien
Postorder ( stut BTNode *t)
void
Exawples
dlEt
Preorder : a bcdet
:
Iuorder cbaedt
Rostorder : cbeda
bio
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
e 4 g
Reor der ab
Jnorder
Postorder
et dbij
tevel
OYder
abe tde g
Trarersal
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Bxample
6
PreordeY: | 2 3 4 5
InordeY: 2 3
5 4 6
Preorder: mno P 2
9
Postorder :
:
Inordei
eovvee pastorder
Preorder trarenal
Rerenso
worden Thordes trversal
Cee
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
m
Paeorder : abeki nct 9 h.
h
(my
e Tree
[Heinht
retuu -1;
e
else
return max( Heiglt(t slehild),o
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
btwode *t)
void Do ( Stuet
bo (t-> kigutclid);
J
I! rbros
lhat wll be te hhal bree att fe
above tumetin
tuee ?
followug tnctis
Conido te n stuct BTNlode *t)
STNOde vod
void m(stet
nltleteild); data);
priut} ("c t m(t>letcild);
m(t>ligltca);
girew tee
Get
tu va wtt) for
ti
BDEA cF
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
m(A)
n6)
PCA )
m(F)
PLe) m(D)
(P(F))
)
Bues
Conaiden tae feleg kutin *t)
m
( stuct BTNode *t) void n( styuct BTNode
void toirt2
printt ("t data );
BDEACFG
wit)
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
1. Binay Iree
Complete
Bnarybee iu wtich possi
counpletly tlad
fe iat, modos
utastlevel pocible.
2: Styict Complt
Buayroeoutr3 s
ee
iw wih eey evel is
bey stict
biuany tee
Covplete
rere i
tree bt
wst
tu
Tree
1
at wdex
Reot
Let ild :
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Tree
3. Full Binoy
also colled mopu binay eong
wode eitinen0 OY
2
ctde
*
Total wumiber o nodes
aloag
dd valei
3-Avy Tre
No 2I+1
K-
AryTee
eacdh node OY k-ildre
wodes
e
iutnnal
L: -)I +|
N kI +|
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
bune
Tree.
Shewed
4. Let wode luld.
utennal
Evey
Let operand
: lett dild
YO
atb*G
atb
b)
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
2+7*3 2 /4
(og
Quey
2- 5 *7/|* 8+ 6^ 3 (2+9)
te 5
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Tre o
Binahy search
elemete tehe t wbtree hare
Au th
tee eot
Valu tea
have
tue iglt bubtee
val
18
5
(23
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Deleti w
BST
wode BST Aso, heep trck
Search tor tu
tehe
t odu
panet
node
Nodeto delctd
ttede to Paut
ttue wod: *paset.
CASE. 1: The
pehent Lehild )
porent
14lwod= ->
ponamt AL NULL
Leild
=
panetRcd NULL
free(woda)
mode Lhild,
else
wode Rehild;
panutLeiild).
L pausutLuild
=
ild;
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
50
30 60
30 65
20 40 55 65 Delete bo r
/
35
Delato 35 )
20 40 55
38
32 38
34
34
o(w)
Sennebig
O(H)
Insesti
jsals
Deletin
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
from preovdw
trorersal Simpt
(utru ctig a BsT
BsT
ae e
lby
Iuent elets
1 BST
The preojde trarersal et
2 7
12
postordu rawrsal)
tosterea assal
12
9
/
2 Lo
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Ques A
4 3 9 13 7
Postor dun troversal i 2
Preorelen
troversal
Preorde
raveral 5 6 3 22 4 7
T23
3 9 18 17:2
m
distivet nt
n
distiet
modes
Tree 2ncn
Binay nt)
uubu
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Ques
when seanclig vale w a BST.
values 0 20 H0 507070
5o 80 q0
8O
traversed
W
Same erden).
possible
m
utuch
ordns
tee seanch path
vale
to coute'ng vae Go
60
No:
No
t ordes possible :
AVL Tee
balamcng ina Searchn Tree
thee
Balauced =
tor each mode
oae toctor
Balanee'tactor
B-f2
6f= O
belouned
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
a
Tree
de to setioM or, deleti
Typu eImbalauces
1- LL Imbalanee ( Let let wbaauce)
LL Rotaten
LL Rotaen
Tnsede0
.
(60
Rotatuen
(45) (45) at s
(2
2
50)
Tu t 90
(40 RR
Yotalu
(6).
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Iwyet 25,
RR Yotou
30 60)
C
LL ten
(60)
LL Yotottn
60 49
RR Yothen
(re) (60
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Exawple
-
(austt AVL tree 3 2 5 6
-2
(4
(6 3
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
, 15,1 6
25 27, 40, 8, 5, 3, 24 ol7i; 15 2,
sor(25
(21os (40)
1(2s) 1(27)
I(40)
(4o)
I(8)
(49)
(13
3
(29)
(13)
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Cases
LL rotao
LL
(ov)
LA
Lo RR
RL
L-)
Fxample
(81)
-2 Delcte 2
5)
RR
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Le
Deltu l
Delstu 5
(4)
(13
Delete8. 6 RR
votet 13
beletb 13
Delt
yo)
Delctl5
4o)
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
nodes
Minimww ubn
w AVL tee 2
H=1
H
Het a
tree 2 3 4 5 7
Mimimuw
2) 4 12. 33 54 88.
.)e
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
HEAP
taee loaued dot stutwe &NE
te
Reot at
mode at wdes
(20)
20 I5 12 G)
2
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
w
Insentow
Lnset 20)
(20)
(10) 5)
12 (2
Insetl5
(y0)
(()
4ujut
Adjust
(12
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
4 |0 3
Butd Mw hep:
Twello
4 lnset3 Adjust, Iustts
(o)
5
3 Adiat
Tuwetl
Runtime complexby
Insenting elem
elemet L
IusectiA n
lmevte
Buildg ap bt o()
WAethod
Deletien
e place tee lart wd
Delate aeet elemt
t Lot
keopti
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
92
trom
T(3)-T( 2)
torwaed
T calulate T(3) -
T) T)
2
*l* L 2
taso
T(3
2* x22
30
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Heap soht
Ruuntine cwmpenty o(nnog) o(dog)
GRAPH
and
inea datan stuctu os.
- [pb}jao
ap
ee dnedien:
Dndirected qap
Eagu
diretn
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
qrap Repreaetaton
Tolole Matig
MXn wati wodsa (vetees
2 3
D
2
3
ewt.
L
2
2 3
30,!
3
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Vet'e
w
aayiveghqrvo
Veytices
X! b
3&
Thavoning
1. Breadth irst Seanch BPS)
inplemudtad
SourceC
CAEBFD
Brs(u)
Mak visuted and Eney
flnd l
wnnsieod
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
DES)
2 Deptt Prst Seascla (
Cimplemntd g taek
Seurce A
Traversal
ABDEFG
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
NASHENG
puovice heeult
u
castut twe
Seanehing techniqyue
os 1, DIRECT,H ASHING
,s5
H(k) 2kden!
c o
posci ble bey t be stored 49
-3
possible ey 3 to 102
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Adv: wito d
isadvi parible
clisien postble
bortta
baslia4
Locati erm
pniteA H
Form
get fe Locatièn n hash tasle
(63
666batuen.
M01TDA9TAUe
tsuwz1o00
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
6
DlGT EXTRACTION METHOD
Locatsn rang
l,3,4
629 8 4 3;
(9JF
694- ocaten
7. MiDŠQUAREMETHOD
Tale pde middle
dgits.
rosriJ
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Collision
situatiu terot wt
tuo ditnt thave
Loys to
inet- 12,5
Dpe Addreasing
Closed Addressng
(opue hasting)
Quodiatw prola
Rad
Deulble
L-
Lineo probing
to toYe ceidd.
Applicate m
Dotlases
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
2-Quadhiatic phobing
L= H(K)
Celicion at L
wtene l,23,4,..
(L+i) wod
sutfeu trom secoud crtuig
3. Random phobi
L= H(k) at Locati
L
Col'ien
4. Double
L=
4O clisiew at Locan
Hx)
--
t=l,2, 3,
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
h Chainin9
oleut wtc have Cawne asth vale ae itred
w
at Locaten
lined lut
pridanq
2
12 wod
102 3
2
13 mod l
Closed A ddre
Open Adaressinydas (Gpe Hastig)
(cosed Hasling)
then ocatim
addresS9e
to loe qeat
locotim tene, othen
to be qemeroteiH 9ldvog
O
Linited iunwoer 4
eemto Oimitd elet!
be red. l tortd
No oveloo.
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Clusterin
segusnee of preoccupad pastio
Lag place
stil at
d. Seeonday utng
Longen, ai wmasdy at
becee
Quadiatie probg
Load Facto
pen slot
Average
ebe ot leys
load ttor
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
tillzaten
Space
arrirsteu.
Cpoee
DSpae
Fox
pe adarog
for closed addresg
eleuents
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109
<br>
Unigorm Hashing
hase tumction teat Locatiu
a
Priyanshu (GATE 2024 AIR 379, GATE 2023 AIR 384) @ https://x.com/Priyanshu__2109