0% found this document useful (0 votes)
31 views23 pages

DS Graph

Good note
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)
31 views23 pages

DS Graph

Good note
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/ 23

Juabo

Page tlo
Date

Grraphs
Deinition:
A grapb G Consisks cf a set V a
Vextices Chodas) and a set b
e coita G (v,e) y is a tinte and
Vexticas
hon ompty sel
vertias, theiy paxs callecd olgas.
Set o Vextitas

An edge eale o) is a pair


tobe incidonl

23

le) hee lae


saph maybe pictonically rapsaseabad
epsesca
Jumbo
Page tlo.
Date

hle hae Aumbered


humbey 9cl -ho
the hedac ,2,4 and 5

he edqe incident coith Nodal and Aede a


cositten ac (l,9), Oe Can also eoniten a (2,D
he Crdosing og Ven kicasis net Qignifitant

2n an wndirackedgraph, pain of vezbias


epaasenking ang edge
, ) and (u', u) sepsasent khe Cane edge
the dirockad graph eack Rdge ic
dexad pais f vextias te) each edge is
apsasenbod Ay a directol pain 74 e-lle)
Xs ibial Vexex the tinsal
extex. Hone (u) and lle, ) xepzesenk boo
dtferant edges

Re dizechion s iadicatecd by an a o ,

the sef a edges ould be.


Juabn
Page tlo
Date

Gyaph Toyminolagy'
Dinccod q1aph A divock ad graph
is a qanh cohich has Cdored pan of yaaliue

the head ie) each edge has direchrcnHaa


a doration oill bo ocscuated
the edge means
So direled raph is also kaeon as digraph.

R. hdieckel goaph: Agaaph eDhick hac


enondared ol vexCias
air of dalled undiectes
gpaph. Supase
Can be oikton

A gsaph is said lo be
3. hleighted raph: A
ceighld is adgan have bon assignad
SOme value
5
Jumba
Page tlo.
Date

path -4
55 kouest Palh.
) 3 +3>4

A Path :
all the intesmediate tai nedes betseor the
izst amd lat hodas na joinadby adges.

Paths
3’4

Qhe palh lengh hecmbax


of cdqes present ìn a path. ae patK Lengba
Maeian in coeighled gapb the palh length
is compat as tAe sum of labels cf the
inkemadake pdges.
Cycles A palh that Staaks and ende oo
Ehe Same Calleda yele.
Juabo
Page Ho
Date

Stonling hede -l
Ending nedo -1

6. Acyclie graph; A graph coikoul


i salled acycle g3aph. A Lree is an
excellent example o acycle g3nph.
Qn

Coop the Stanting ancd ending


axe Same kon the
hodes
Rdge is Called

8. Rrallel edges: p thexe axe mulipla algu


betwo Che Same pan ol hodar inagrpi
then the edqes Qne called
calle paallel pages.
Roo paallel edqes blo
hode 0 ond
a.Mulli gxaph: A gsaph Contahing se7 eop o
parallel edges bolh is allad
al a mlligai
Jumbo
|Page tlo
|Date

iorSinple graph: A
A sipla
Simnpla grafh
qraph is a43oph.
LOkich is fsee from gelf leops and panallel
edgas.
Degsec cf goaph: In an Undisecled graph
the hemboy of edger Connckod to a hede s
Called ils degs0Q. The mazi num
hode in a qiaph is callecd tha cdigreaf
the
În diracbed graphethexe aue boo
-degsces af a node ingue and outdagsa
as the Aumbar cf cdge
incidonl cepon Qmd Cukdgzae
hember gadiating t a a Acda.

a, Pondent nodeÁ ponlant Aode in a qsaph


is a hode cokese indegzces L and outdoqsa
Juaba
Page to
Date

Repmes enlalicn of Graphs


Agraph Can be vepsesentcd in rnany coay:
and he most poplas melhodo ne
) Anay-based epvasentalon
) kinked vepacenlation
tii) Set epresentation
DAnaybascd 3eprasenkalion
A graph an be conyorlably epresentol
using an adjacency matix inplamenled thacugh
a too-diman sional arnay
A qraph of orderN haxing A hadaro
Can be modolod a a squano matiz
yertiues
Of Veatiac Con
valwes
bane cnlg Booloan
adge hetcon Vipind
Dtharoice

B
BO
B

Direcled Graph
Juabo

Date

B
|

BQ D B
C

Cindineelad Gnaph
3) B D
D
A
B

Maigitod Cnaph

i) Linkeel Repsesenkabion
Cnkd
Lists is used to gepsesent the aacont hadac
and the daba stuckine is callad adjaccacy

B He| NULL
D E NULL

NULL
Juatn
Page tlo
Date

tëi) Set Repsasenlalion:


hes sepscsealabion follenss -ha dofoibion c4
the ikse H in the sense thal it tnaintosns
Cioo &ets

E- (0,D), (B,A),(B.),C,D),

havexsal of Gaaph:
Meansthal Ono Visiks tho
Trellinga gaaph.
yexticas of a gxaph at laost oho. The papase
of the Lael dependo upon bha ingormation
stoxed ia the graph. Alooadayc to saach og
aidaly used in abifcal
inteligenagroph can be Erayessed in mag
A
LDays bul Chaxe ane Coo popular methodi
ohich iaidaly isacl forseaadking gsapls
BreadE, Fixst TxcNeKsal (BES)
Q Depth Eisst Isawensal (DES)
Juaba
Page tlo
|Date

LBroadth Einst S eanch (BES)


BAS
Q g3aph Eraversal algosiha
that sants rom a vantee
3oot de) trarersing
Chon Cania
the graph
on to ibs adjacenl
Wenticas ie) follocas tho Aet veslen on the
Same level. hichia Q loveL, t traals all its
Siblings and Chon movs lo the hexl leval
Cnco tho seasch Space ofck a lovel is eehautel
the trawel kor the Aeel lovel Stanks. This
Conrias Ôn Lill all tho vasliuar hae beon visitad.
problcn the tranel
up in a qce.
n order bo avod yclac e may manbaie.
L0o queuoshotvsited and vibec.
Algcithm
BES CEixst Vestex)
add Est veatea Qn holyisit ecd
placo NoLL on Visit od
bhilo Cnolvisitecd NOLL)
X2Moe

qeAesale adj aconts cf vostex


for pach adiaconls of Voséor do
on vaited
PND jacnt is ne psent on netvisted yon
Junba
Page tlo
Date

Qdd Gjacenl at
at Rec on not visil od;

poosenl on visited) Then


nol paogon
iK(veatex isis nol
add vonflex Visited,

Let us Consides fhe g3aph

alee staat sayeoith yi 2Es yestias

ale piclk on thase Sa


hle visit both e go back bo he demaining

he cenvsitd acliacent
Ccnuisifd alrcnt eaticas
Juabo
Page tio
Date

and Vy. Thens (he


qenenaked is Vi, Ma, Vo,Va, Va, Vs, Va Ny
Hese lOe heod a guee, Ond oddd CuhUisiled vost1as
adjaccnl lo khe Che juct Misit ad ot tho Teas
Qnd ad al fom lo Aind the hexl Vortex to

(V5)

an

9. Take a booloan coill Aava value tul


ansay it bil

hase a e Pale
Fo) iË o hode Aas hek ba visifod.
3 Tribiall the quecco eapty focnt-LPon
LA.mao Algositkm)
Stoating ede iabo kho
2.Delet front lamenk from the
Ond tnçant all ts cenvisitacl he ighbouns
into tho qucue at Yeay ehd and tavese
hem plio veaify he visik od Ngda
Repcak stlep 2 Centll the
tho quea enaty
Jumbo
Page No.
Date
13

(A hot_vsied
D

Visited

BD hot visilod
A Visited

DFc hekvsitadJ
AB aited

hetyihzd
B ABp

B
Xislfed
-Juabo
Page tlo
Date

bol visilocd

[DR DCE

hotvisitedl
B \isited

het vsitad

Durin the execabion of the alesithn eack


LAodeN eoil be in Ore Chaee staleo alled
Status fallas
SAAUS H (Reay state) he inital &tato the
hode N.
StAqUS -2 (waiting State) The hode A is
the queue os Stack, loaiting to be protasal
SAUS -3 OleSSed Stake) The node hae baos
processed.
Juabo
Page tlo
Date

16

BES Dlgoithm:
ThAS algoithm exeabas a
G baginig at a chtig
Seanch on. a qaph
NOde A
L Tai kiale all nodas to Eho reody (9mus-t)
Queue and
a. Put the staaling hod A in
Change iks status bokke coaibing skate
(STATUSz )
3. Repeal Step 4 ano S cenlil Qaue is empty

N and change the Stakus of A


Process N
bo the poocassd state (Sreros =3)
Quece all tho
heighbos ef A thal ane in the. Rody
State (eIAADS-), Gnd chage Eheiz Stalc
to khe elaiting Sbake (STATOS
Jumbo
Page tlo
Date

Algosithm;
This algovithn exe cutes a deplh frast Saanck
On a goaph G G beginnisg al a stat bede
hode A
H Initiali 20. al nodas to the geody slate(3pnus-)
Q Push the stanting edo A Cnko séack. and
Change its Stalcu bo tho cwaibing stale

3. Repeat steps_ 4 and 5 Lntil STBCA is knply


h Pop the top_hode N stpck Procass A
Qnd chanqe its Statur to the peoca.sced
stale (ST ArUS =
5. Push oato sIAck all the heighboxr o N
that ane Still in the. Teady stabe
(sie10s=1), and change thai stabus to tle
b.it.

Adyacenl Vexkias: Vastes V is Said to ba


adjacenk to a vertex Y if khore is an edge
a)

Venticasodiacent
S , 3, 5 and b.
Page No, Juabo
Date

Deptk frnst Seanch CDIS) coth Eho inht


2 DES algovithm stonts
to dospoy
ode of lhe goaph the
Cha goal hode o on
Qnd doepes tentil coe findno ldnen. Tho
the hodle cohich has
then back bsack fxom the encd
algoithm, Dede thal is
ecent node
Cooando che ast
yek to be complately neeploxel.
SuccesSorS LE travela thoY
aithin
SuccesSos md So Chus Ehes
Same as înoxder Cranel o a trea and thaokz
the seaach goes dacpea inko saosth bill ao
Succassox iss fourd. Once. thaseaach Spaceat
a vexter is exhauskd, he frasel for not yotax
stogbs, This CanTias tillalo Vexticac have
becn isited.

Algonithm DES Ltist voabex))


add tinst Verten on hot Visited
add
ploe NDLL oA Vicikad
cohile (hot Visitod NULL)
emov2. ventex from notVisitad
gehey ate SuccesSOrS veabex;
fo Rach SuccoSoN Vesbex do
-Jumba
Page No.
Date

H (Succassor is hot paesent cn. Vesitod AND


hot paeSent Cn hot Yisltad)_heo
addvestose. foont nol Visitad

itverbax is hot present on Viaited) Then


add eyetex Vesitadt

Conaider tha 93aph

Tes ada conl orticas ane , a and Lak ceg

2.Tks adËaconl Vextias


Visited kot us pick Vh

VisitodLot s pick Vs
alrady
Page No
Jumbo
Date :

alseady visited . kal cs


5. Tes adjaient Vesticas ane Vg, , Vo Both ane
alseady visil ed. kesefore
ale had e and V tanvisitcd in the ct s
lale may Visit
adjaente Dbvioucly
Choiois Vg

Algonitton
Step I Push stastiog node inko kha skack
Step î : Pop anelemenl foom bhe Skack
(IE oil pop up all yexkicae faom tha
Stack okich do not have adiatonl
Ventitas)
Step u : Noo psh all the
hode f the poped element cn
Stack. push che elemOnt even
n thestack.
cenlil stack
is emplg
Juabo
Page tio
|Date

DES

ip

sinp2

Step5

2
toccE
Stepk.
Step&
D

DCCERED
Page No. -Jumba
Date

Ppplicalions
L Model Cf A : The tooclel of coorld LDida lo!
Can be Teprasenbad by a g3aph Cdinected)
Ohesein Dodas denole ehe documenks, papens
asticlas efo. and tha ecqas Tepaacet the
Dukgoing hypesih ks bebcoecn thom

Site Sy

bo
pages
his hegpaxlink Stauckxe s tho coek
styuctae Sinila to tha coeb creatd by a
Spidox and Aanco the hame. Loorld oida czb.
Rasouto allocakioo qaaph: 2n ordes bo dabeck
and avoid deadlack, the apexaling Sysbem
oaintaias a
hat ane actie lo the Syctem.
Coloaing of mapsi Colouaing f maps is an
interesting pooblam cohen eim è ià dosired thata
bap has to be Colocned in such a fashicn that
Juaba
Page tlo
Date

ho Cwo adjacent Counlias Or egons have the


Same coloun. The Constsain is to s rinimutn
humber of Coens. A map can be epresenkad
raph coohenein a hoda nep esenke a gior
Ond an Qdqo betoccn tuDe 2egiont donote that tho
tooo cgicns an2 adjaené .

4 Scene rphs: he contents ß a liscual Scenc.


Dre also manaqad by esing gaaph data stuctac
Vixtual Reaity Mooleling Langugye (VeM) Sippeas
SCONe. qaph progamming madal. This mdot is
esed by MPEGe -l Co epIarent mulbimcde'a
Scene Cemposition.
Junbo
Page tlo
Date
93

5tacobook: Clsens ane Consi desccd to be tlo rtitas


vontites
Ond if hey faiende then khore is an
eNaing beteoecn Chem. facebock riand sdt,
dgcoihm tusas graph Cheorg facchcek io an
ianpe cundisecbod foaph.
b. Gcogle aps: usas gaaph for bui lding branspeskai
Systoms, eohene inlescecfion kroo Cos rerc)
Considored
SoadsQhe Constdor ed Cobe
o be aa vetex and tho
Oad eonDecting
be on edge, thas Chain,Davigabinn aykem is
based on tho algoithm ko calcelale tho
sho bast path etuoRen kuoo vexticos

Bagides aboe, the otkon popaan applicabten oe


i) Shestast path proklem
) Spanning brees
i) Binany dacàsion gaph
g
h) opolugical Sosting ofa graph.

You might also like