0 ratings 0% found this document useful (0 votes) 15 views 20 pages Unit - 4, Data Structures
The document discusses various types of graphs, including directed and undirected graphs, and methods for graph representation such as adjacency matrices and lists. It also covers graph traversal algorithms like Breadth-First Search (BFS) and Depth-First Search (DFS), as well as sorting algorithms including Quick Sort and Heap Sort. Additionally, it touches on external sorting techniques for handling large datasets that do not fit into memory.
AI-enhanced title and description
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here .
Available Formats
Download as PDF or read online on Scribd
Go to previous items Go to next items
Save Unit - 4 ,data structures For Later Iw
neg rode womatt i
Be ne webct jotneds - edges
yp od joe Ken
540? ted acterloe ee vertices and edges ce)
Ber 8h a fahke nbArewple reek ab Nerlices
there tie Sentke non - empl getot edges:
ae *
4 the nodes
| Peek 3. Nrevitee 8 Ove nothin bo
yer tice Sj 4 |
fm the qverh py wert “ove joka ed by edges.
rAgoeny ; io Se Ge faney
Ree
ea Ny ate gery
Types of Graphs : pide
Sa sfeally Graph ave 2 types
(Oyelseacer) soph < Celtectten 8 er
® ondwected graph. ;
“eyes 4 :
Tn whected graph the dtreatfa pis) are: shorn ov
edges
ud
@ scanned with OKEN Scanner3)
¥ vio} jhe olde
= ey . ’
. Lndfrected graph, edge, are non dtrected lig
Cow, rok .Pri oles 1. = eee el a
; 1 Ls ; aaa
. , a
L pi
’ . a
x Graph my plem entotPon method
cor) n= 5
Graph nepre gen talon “ynethod- «
The normal the grape cay, oe eyrreseated by
2 xe presen tatton'¢ one Ps the adfecency
matix and od one Adjacencey Pat «
1) Adfacen cy matty 90 away roe:
2D Adjacency \*st J
eto HES ese pre Senlatfon ‘rake Gee 2. ain engtonal
errr 28 Lsed to wepregents the ordph j
Suppose for example) Con eficl ev. tne green Ca)"
ot IM \rerthees, and the mokn¥ oe {yy 7th 3
Yheve 93 09 edge present belween tne ’
Nev Wee S Yrond NI4 , then meryeeye oa Be iz
MSY ETY mevlooeil> 9 Hewsle aon, boty aity 4
L i
@ scanned with OKEN Scanner|... Ta
eo trat for an on dtrected roe xg roph £34- i
then for om 34 NY Seago ae
? ea
\ >)
we Os)
|
5} - Cpr ara
> AdjocenL mats?x doy neg Led graphs ~
Negnd!§ ove cfiekan cee ave qven along ever
Edges an adSacent ee Je senteetae
any edges when %s present ble, =
Mev Pees MPRA TS denoted by ets wetgnt 8
em gty egy or caagne sof Rye
i to ee zi
=~
Mi)
s mao! ome
2.
PO ONS "= Ge eee
= CRS OQ ROO
O Bt 9 0
as ,
S|. 2° BS oF aasia
—_ a
@ scanned with OKEN Scannerlannphe ae 336
a oF 38h br 2aphs p
beehes “bare forrno| a. :
Guaph trovergal meine
ie have wo ype
lores
© BFS —eereath fet Search >
6 org oe cegeth & pick ae |
Bie - Eo ers we _stoot re pore! I ‘
be Find cal the adjyeent werticegoht cna
proces? yal oe sepegted For atl the veBees
80 that the verttes print on ~sesuit
° at Saph 5
> For ovefeding sepetiton of wevttees wie m
| amay @ of Vigi ted nodes . =
@ scanned with OKEN ScannerLy paueve data giyocttre Ps used, to store Odjacen|
| veriives-
| Algossthnn ‘
Jy cveate grep depending on the type at qr2ph
r get the valve of the Haq hos either, cero oy
| Oe pol ee
a 2 ‘
Ne
= Read the verttx Prom tthe Yoo wont +o eset
the graph soy Vi ont |
_strgultge the Visited omey] tothe 4 fotedex out
| intial
> wget the Visited AU? Pate alveve -
s ag at the hont of the
ey plkich 28 at the fron
Us vieste the vertt™ vi
a Aglete 12 4 On aes of the alveye and
HElETE I, So. e) alueve
piace the adjucert, nodes. 20 th 3 ‘ :
BAR the aueve ts 1 + Erp: cy:
= Fepeat the’ step
SPI. SAoit efth vertex © Yngert vertexo tthe
Alveve -and marked % the Index of vistled
aw
wray by 4. :
pe! i: oe, | \
i
et to
3
ae Result =o
al
- al
@ scanned with OKEN Scanneruspeeent verdes of vertix 0
e
L nose Zlement&
he zero pital on
gkeprs-” find oot th
3,
mork them sfetted inser
Prato the anweve delete t
7 vegolt rt
Jaq. KET
Re solk,= 01.3
eae me alot
StepS ~ vigthe thei. find out the adjucent
modes, of the ale aducent riod? & aire 07.85 257 6
thoge elements Sngerled Snto: the. atveve: the.
vistled node a fndex 8 moked Pn oway one-
Aeleke 4 Prom the alueve print on the result -
@ scanned with OKEN Scannerse
geet (LY the & ptadool the adjucent node of oe
| gtep™
: g BAe 61,4) O delete the 3 Siehs ‘ntoedé
rane the @ Pn analy Rndex stalve Pe 4.
Ceiete the s and prin b the wesult -
Regu tt = 018256
geavch )7- =n keel Boot Seo eh “Lravress]
sovergal Ane path
one VerteA ond ©
when there $$ 00 vertex
pes (oepththet
we glort From
aS deeply 08 We cen Qe*
Pov si 4 and geareh Lov onviahted
woerttX +
og main Pn for ator 4 eos
e kxovel ack
ratted
VAN ova
Neri exs 4
as deeper and deepe’,
Hepa $a) rn! oF S, WE ult!
| be posh
Reh we ae vragttin
trio the stack ater trot Expl
dine 9+ Xo wth
oe! tnede: 2
Tol pil be explore 24.3.0
I
@ scanned with OKEN ScannerShepo — Vat tne'4~ 4 util, be pushing trio
the ee Satter trata wi be explore 632.5,
|
Yoo gelect one vertex RAL ¥ & 8B Veet £ the 3 :
Brchs ye eeplor’” Ne ce ©. 2/H 4
nlext wwe will vist thea. 2 oil be oa
OA Lo PRE Sack * [a
3 ' |
= |
; S|
Stepur—y! wisted posring on the gtack
abler wnat viet Soor explore the U2 2, 3-6
gles Aieththe 6+ posh onte the stork
6 dees nol have ony forthe vertex then Well
the bacre pelete the 6 from tre stack
the wcesult- 4 does not fore OY unveerted
2 bac tracking pelete Prom
| shen-Next 2° 2 paving the ane wir etled Vertex,
that °8 5-5 ull] be rough Pnto.the stocks then S~
sagaee heve ony ante fled were x then S HIPll be
detet%g chow, shack > print en the’ seer beretheneeane
sprint on
wertexs then apply thi
apply: bac Arociciag then sear Ch Soi thenun weer eich?
apertex 2° A eft pe aeleting on Bote’ oprfnb- Ons
ae wesuit’ {hen app ry Jo acls saa. eK EG e
ad
@ scanned with OKEN Scannerf Jpeve Pe no vowsiled verlex of
wtege ter 4. theve PS 7 Cx of te
soling
onthe negutt+ gain we are
ext £fadout he ony.
King on Jhevesult ,
ther
| peteling 4° P ;
opp ly J joacke fyeckin
yrevtex oper wrendelete the O° pen
nen Afrally glack*S empty:
sited
gn
|
@ scanned with OKEN ScannerAs IE. SonTING ae
a—s —o—orrnr—
De bihtlfons — The gol
the (et of elements t
sea echtawe by which we expect
obe arranged agwe expects
bol the awengm ent of the
sorting ovder °8 noth
element % Som & Speckhic manney*
% vtec gort f=
thm brat uges the deiPde
fog algo?
+ tn ths me
BIRT]
ern l= |
Poker govt *S Sart
and conavr® Strategy thod dv?e%on 18
yy Cor reed oot
AynarnPeatl
alge thm Pov ast Sort?
afutce gort Clow gn)
t
zh Clooz Regh) then
Ke= portion (0/100 negn) 5
atwrek Sort Clow 0)
alutac Sort CKH! arign) ®,
y
J
2 Sorting SY Par bt ehfortieg 1
p\gektinms—
PastPtfon Co, toon )
Plot = a (lon)’,
Qo = 10%)
ub = neyh >
esrPie (te zoubddo
wrtle Ca tae) ~ = pivot)
t
@ scanned with OKEN Scanner8 eG
jaye 2b
. ‘
ea ca Cus) S = pivot)
wo!
Bue Ia
sheapene) ther
gunn}? (10 HANDS
s
alrowy= of eas),
a fubl = prot?
Sector vo,
Pi
% Example
conser ane lPet
| 82) bos SxS 42
of ungorted element $O8 6% 14,42, 8,
28)
her & low
eo witl congedex pivot =o Ttow) &
©
vence 62 °8 o prot ele enent*
on a a e ‘— ,
prot A
a
@ scanned with OKEN ScannerQr_| 60 | Bo. [tz id
ee ee
{os wl sl] $2[62 6 [ao[ 2] a |
ie <2 ene |
subitst4 Sob1P8b2*
er bo ag prot for gob\'sta and |
ace prot at prope” posPlons |
pol mean all the elements that
should be left etde/ and all the |
ater phan PROS ove ot vight ‘|
nlaw we wFll consi
ssepeat conove Step & to pl
prope® pos? Hon of
ane less ERED Prot
element $ trek are gre’
ghie of pruok rence weget > |
yee:
ELETEEP Sy 2 ®
SLSR! ol
est |
SobVSt4 eee
plow, from gublist AL Element 42 become 8 pivot
glement ond we Utht Bort Soblis tay
Pael Deak ZB Cae e
Shee |
}
. gunners
now we well congdder gokitgt 2 TA the [gt
agetn gr becomes a pivot eementowe Pll |
}
4
@ scanned with OKEN ScannerL the eroceduee OF parti Yo) on Sy Uli it aan
mepe’
ae -— 1 ip 4 + 8
[32 [5s (Sales [e ae | yi
at el
ieee!
ee aye
at PLS proper posre® o ot
thos Be PS placed
we get eorted tet
Yeapsort’s — i
Heap sort 78 Botte 4 metho d<
2 etuoork $ Pn nsteqes™
— Prat con gtxoct a heapter
2geavered by Sud
wrdivan &
4) eapcon gfsoctfon *
qeen nombers*
2 weletfon of agen keys delete woot Key always -
for (9-1) mes bo semarrrr G reap + pence wel)
get the element $ PO decree sin onder to a
onay mn plementalfon of heaps delete the zlemeat
ped gtemend In
Liom hea? ond pot the dele en
ane best postifon 8a porary + thes after acti
al the element$ one hd ones THE Colleck
nr
these deleted element$.in anariay Sto
@ scanned with OKEN Scannerfrom lagt ondex of array we wil qet a ho haat
@lements fa aaseen dfog ode’
Wapeeen? ace Heap cong yuelfn
petetfon of maximum key:
tek vs underston d thPS Lechriave with the help of
example *
ex tort the follow 4 elements vefng
15, 20s 3.4430
° a
Mou Property ¢— parent node #8 akoays greate ror
gatval to the cH¥Id node"
heap gor t+
Heae congbroctPon3 =
skepay— wnsert 1S
15) emgert the element 2° |
@) Crhicay fst we will 1asext
lett Held )
steprs—
Now Check the roxnopety +The not
gatig fe3 the maxmurn property * then soap
the elero ent ’
15%
iQ <2
Ds
eer ORR Teme mnfjroperty ? ng
gards fed ro need nob
be Ca
@ scanned with OKEN ScannerIder tne aozisci-e) child node PS grectet than
porent node: $0 8.aeP-tne elements
a
® ®
@..®
Saserted “But 2058
Sep 6¢-
All 5- Zlement& axe
greater than r0- 3° Boal? 8 aod 20
@ scanned with OKEN ScannerDeleifo of morro key"
So
is Delete voot nade So last Will be Placed %5
4s
® “ Sine
pe ee
Coeleted node wil be
ptaced at last]
@
nlow chee the most roperty T20°8 qreates than
é gwop the elements:
P Focus
eleprs— oelele the toot nade 26 and fngert the
fast node 40 the root node>
@ scanned with OKEN Scannera % ii ia
<
Rprpe ty is not galig fied u04p 1s and 7
$4
all Glee
es ¢, ERE
|step6t—
1S)
| oeleke root 0:
| Po tay
peers = gap the Elemente qand +
2) 6
2s oe q sod nse
deis-end casert last node +
ae the iret oe
“aEexternal gortfags —
external sorting hondles ©
9,
th?g data may be 4° brg
°,
Cornporeng device for sorting
: { | memory Cusvally type or OT)
a hy bifd ~ Sort
massive amount of data,
to fit &n RAM of the
°,
86 dala wostde OY
Slower externa
Q
externa | Sorting dyprealty oses
rr phage »chonns ot data 8mall enogh 0
x Si
ape cea ard ead > sorted ord wllten on
otf
temparary) fle?
3 xn the merge phase the gorted Subffles are
combtned Sato stgie large ffle-
External Sorting 3 external meig & Bort algor?thms
arigorttnens—
mevgsort CibtUEd/>
mege Sort cad, mPd)5,
mexge¢ Sort ca-mid+lubs,
merge Cate. mid 2b)
merge CA) Ab nod U8)
Pelb3 banka’,
hades,
wile (?z=mPd darje-ub)
é
We Cane
ixy =al*d
Paes,
e
else
t
@ scanned with OKEN Scanneremma ty
| eed =o) '
suo
§
ze
4
y
exge sorts
owwratag ¥
Wmerg*ng of the!
gorted BSE
owte and conalueY method -
ven Wet eno gobi'8 ’
ge goPlhst 4o ge
kone com plete
Be ter -
We Can \Pet dee =
haven! tel MEM ween
GE yews Gc gach [gbBe Nr
msCo8)
]
|
mstor) mecs, BV, merg s (ond, ) L
) megetov'd a
mac5%) MSCVB) merge
Co 678)
m8OV mse
Bemba |.)
merge 65/518) Np ,
)
met vy ™5(B.8) |
™meviehig)
ms CU)
Bt”) msc gio) m3 (33) merge (33,4)
|
merge
} \
eto) msc) €0.0,\)
@ scanned with OKEN Scanner