ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:192
Unit9 TreesandAlgorithmsStructure
9.1 Introduction
Objectives
9.2 CharacterizationofTrees
9.3 RootedTreesandApplications
9.4 SpanningTrees
9.5 AlgorithmsforSpanningTrees
SelfAssessmentQuestions
9.6 Summary
9.7 TerminalQuestions
9.7 Answers
9.1Introduction
Trees are extensively used as models in area like computer science,
chemistry and in search procedures. These are also useful in design of
widerangeofalgorithms.Inthisunitweprovidesomecharacterizationsof
treeswithsuitable illustrations. Wealso introducedaspecial typeof trees
namely rooted treesand binary trees. Wegive fewapplicationsof these
trees.Thespanning treesare introducedand thealgorithmsforspanning
treesarealsoobtained.
Objectives
Attheendoftheunitthestudentmustbeableto
i) Study the connected graphs without circuits (called trees) and some
properties
ii) Characterizeatreeofaconnectedgraph.
iii) Knowfewapplicationsoftreesinrealm.
iv) Knowrootedtreesandsomeofitsapplications
v) Analyzeandwritealgorithmsforspanningtrees.
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:193
9.2CharacterizationofTrees
Theconcept ofa treeplaysa vital role in the theoryof graphs.Firstwe
introduce the concept of tree, study its properties and some of its
applications.Later,we introduce theconceptof spanning tree,andstudy
therelationshipsamongcircuitsandtrees.
9.2.1Definition
Aconnectedgraphwithoutcircuits iscalleda tree.Acollectionof trees is
calledaforest.
9.2.2Example
Treeswithone,two,threeandfourverticesaregivenintheFig.9.2.2.
9.2.3Observations
i) Atreecontainsatleastonevertex.
ii) Atreewithoutanyedgeisreferredtoasanulltree.
iii) Thetreesconsideredarefiniteandatreeisalwaysasimplegraph.
9.2.4Somenaturalexamples
i) Thelistoftheancestorsofafamilymayberepresentedbyatree.This
treereferredtoasafamilytree.
ii) Ariverwithitstributariesandsubtributariesmayberepresentedbya
tree.Thistreeisreferredtoasarivertree.
iii) Thesortingofmailaccordingtozipcodearedoneaccordingtoatree.
Thistreeiscalleddecisiontree(or)sortingtree.
Fig.9.2.2
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:194
9.2.5Theorem
Inatree T,thereisoneandonlyonepathbetweeneverypairofvertices.
Proof:Suppose T isatree.
Bydefinition, T isaconnectedgraphandcontainsnocircuits.
Since T isconnected,thereexistsatleastonepathbetweeneverypairof
verticesin T.Supposethatbetweentwovertices a and b of T,there
are two distinct paths. Now, the union of these two paths will contain a
circuitin T,acontradiction(since Tcontainsnocircuits).
Thisshowsthatthereexistsoneandonlyonepathbetweenagivenpairof
verticesin T.
9.2.6Theorem:
Ifthereisoneandonlyonepathbetweeneverypairofverticesin G,thenG
isatree.
Proof:Assume that there isoneandonlyonepathbetweeneverypairof
verticesinagraphG.ClearlyG isconnected.
Ifpossiblesupposethat G containsacircuit.Thenthereisatleastonepair
ofvertices a,b suchthattherearetwodistinctpathsbetween a and b,
whichisacontradictiontoourassumption.So G containsnocircuits.Thus
Gisatree.
9.2.7Theorem:
Atree G withnverticeshas(n1)edges.
Proof:(Useinductiononn):
Step(i): If n =1,then G containsonlyonevertexandnoedge.
Sothenumberofedgesin G is n1=11=0.
Step(ii):Inductionhypothesis:Thestatementistrueforalltreeswithless
thannvertices.
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:195
Step(iii):Letusconsideratreewithnvertices.
Letekbeanyedgein T whoseendverticesare vi and vj.
Since T isatree,byTheorem9.2.6, there isnootherpathbetween vi
and vj.
Sobyremoving ek from T,wegetadisconnectedgraph.
Also, Tek consistsofexactlytwocomponents(say T1 and T2).
Since T isatree,therewerenocircuitsin T andsotherewerenocircuits
inT1andT2.ThereforeT1 and T2 arealsotrees.
It isclearthat |V(T1)|+ |V(T2)| = |V(T)| where V(T) denotesthesetof
verticesin T.
Also|V(T1)|and|V(T2)|arelessthan n.
Thereforebytheinductionhypothesis,wehave
|E(T1)|=|V(T1)|1and|E(T2)|=|V(T2)|1.
Now|E(T)|1=|E(T1)|+|E(T2)|=|V(T1)|1+|V(T2)|1
Thus|E(T)|=|V(T1)|+|V(T2)|1=|V(T)|1= n1.
9.2.8Theorem:
Anyconnectedgraphwithnverticesand n1edgesisatree.
Proof:LetGbeaconnectedgraphwith n verticesand n1edges.
Itsufficestoshowthat Gcontainsnocircuits.
If possible, suppose that G contains a circuit. Let e be an edge in that
circuit.
Since einacircuit,wehavethat Ge isstillconnected.
Now Ge isconnectedwithnvertices,andso|Ge| n1edges,a
contradiction(tothefactthat Ge containonly(n2)edges,bytheorem
9.2.7).SoGcontainsnocircuits.Therefore G isatree.
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:196
9.2.9Definition:
Aconnectedgraphissaidtobeminimallyconnected if theremovalofany
oneedgefromthegraphprovidesadisconnectedgraph.
9.2.10Example
i) GraphgiveninFig.9.2.10Aisnotminimallyconnected.
ii) GraphgiveninFig.9.2.10B isminimallyconnected.
iii) Everycircuitisnotminimallyconnected.
iv) Everytreeisminimallyconnected.
9.2.11Problem
Agraph G isatreeifandonlyifitisminimallyconnected.
Solution: Part (i): Assume that G is a tree. If G is not minimally
connected,thenthereexistsanedgeesuchthat Ge isconnected.
Thatis,e isinsomecircuit,whichimplies G isnotatree,acontradiction.
HenceG minimallyconnected.
Part(ii):Supposethat G isminimallyconnected.
IfG containsacircuit,thenbyremovingoneoftheedgesinthecircuit,we
getaconnectedgraph,acontradiction(tothesupposition).Thisshowsthat
G containsnocircuits.ThusG isatree.
Observation:To join ngivendistinctpoints, theminimumnumberof line
segmentsneededis n1.
Fig.9.2.10A Fig.9.2.10B
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:197
9.2.12Problem::
Ifagraph G contains n vertices, n1edgesandnocircuits,then G isa
connectedgraph.
Proof: Let G beagraphwithnvertices, n 1 edgesandcontainsnocircuits.
Supposethat(inacontraryway)Gisdisconnected.
G consistsoftwoormorecircuitlesscomponents(say, g1, g2,, gk)(herek 2).
Chooseavertexvi ingi,for1 i k.
Addnewedges e1,e2,,ek1 where ei= 1 +iivv togetanewgraph G*.
Itisclearthat G* containsnocircuitsandconnected,andso G* isatree.
Now G*containsnverticesand
(n 1)+ (k 1)= (n+k 2) n edges,acontradiction (sincea tree
contains(n1)edges). Thisshowsthat G isconnected.
9.2.13CharacterizationforTree
Foragivengraph G,thefollowingconditionsareequivalent:
i) G isconnectedandiscircuitless,
ii) G isconnectedandhas n1edges,
iii) G iscircuitlessandhas n1edges,
iv) Thereisexactlyonepathbetweeneverypairofverticesin G,
v) G isaminimallyconnectedgraph,
vi) G isatree.
Proof: (i) (vi)isclear.
(vi) (ii)and(iii):Theorem9.2.7
(ii) (vi):Theorem9.2.8
(iii) (vi):Theorem9.2.12
(iv) (vi):Theorems9.2.5and9.2.6
(v) (vi):Problem9.2.11.
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:198
9.2.14Problem
If G is a tree (withminimum two vertices), then there exists at least two
pendantvertices.
Proof:LetGbeatreewith|V| 2.
Let v0e1v1e2v2e3 . . . vn1envn bea longestpath in G (since G isfinite
graph,itispossibletofindalongestpath).
Nowweshowthat d(v0)=1=d(vn).
If d(v0)>1,thenthereexistsatleastoneedge e withendpoint v0 such
that e e1.If e {e1,e2,en},then e = ei forsome i 1.
Soeither vi1= v0 or vi= v0 v0 repeatedinthepath,acontradiction.
Therefore e {e1, e2, e3 ,en}andsoe,e1, e2, e3 ,en isapathof
length n+1,acontradiction.
Thus d(v0)=1.Inasimilarway,wecanshowthat d(vn)=1.Hence
v0,vn aretwopendantvertices.
9.2.15Definition
LetGbeaconnectedgraph.Thedistancebetweentwoverticesvandu is
denotedby d(v,u)andisdefinedasthelengthoftheshortestpath[that
is, the number of edges in the shortest path] between v and u. In a
connectedgraph,wecanfindthedistancebetweenanytwogivenvertices.
9.2.16Example
i) ConsidertheconnectedgraphgiveninFig.9.2.16A.Heresomeofthe
pathsbetween v1 and v2 are(a,e),(a,b,f), (b,c,e),(b,f),(b,
g,h),(b,g,i,j),(b,g,i,k).Heretherearetwoshortestpaths(a,e)
and(b,f)eachoflength2.Hence d(v1,v2 )=2.
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:199
ii) ConsiderthetreegivenintheFig.9.2.16B.Here d(a,b)=1, d(a,c)=
2, d(a,d)=2, d(b,d)=1.
9.3RootedTreesandApplications
Rootedtreesareextensivelyusedinthecomputersearchmethods,binary
identificationproblems,andvariablelengthbinarycodes.
9.3.1Definition
Atreeinwhichonevertex(calledtheroot)isdistinguishedfromalltheother
vertices,iscalledarootedtree.Inarootedtree,therootisgenerallymarked
inasmalltriangle(orsmallcircle).
9.3.2Example
Distinctrootedtreeswithfourvertices,weregiveninFig.9.3.2
Generally, the term treemeans treeswithoutany root.However theyare
sometimescalledfreetrees(or) nonrootedtrees.Averityofrootedtrees
(calledtheBinaryrootedtrees)isofparticularinterest.
j
b
d
c
v2
v1i
h
k
g
e
a
fFig.9.2.16A
a
b cdFig9.2.16B
Fig.9.3.2
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:200
9.3.3Definition:
A tree in which there is exactly one vertex of degree 2, and all other
remainingverticesareofdegreeoneorthree,iscalledabinarytree.
i) TheFig.9.3.3representsabinarytree(sincetheonlyvertexv1isof
degree2,andallotherverticesareofdegreeeither1or3).
ii) Thevertexofdegree2 (that is, v1) is distinct fromallothervertices,
thisvertex v1 istheroot.
iii) Inabinary tree, the vertexwithdegree2 servesasa root.Soevery
binarytreeisarootedtree.
9.3.4 PropertiesofBinarytrees
Property(i):Thenumberofvertices n,inabinarytreeisalwaysodd.
Property(ii):Thenumberofpendentverticesis21n+ .
Property(iii):Numberofverticesofdegree3is =np1=n(2
1n+ )
1=2
3n- .
v3
v2
v4
v6v8
v5
v11
v7
v1
v10
v13
v9
v12
Fig9.3.3
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:201
9.3.5Example
InthegraphgiveninFig.9.3.3,wehavethat n=13, p=2
1n+ =
2
113+
=214
=7.Thereforenumberofverticesofdegree3is2
3n- =
2
313- =5.
9.3.6Definition:
Anonpendentvertexinatreeiscalledaninternalvertex.
Observation:
i) ThenumberofinternalverticesinaBinarytreeis
21n- =(p1)where p =thenumberofpendentvertices.
ii) InthebinarytreegiveninFig.9.3.3,theinternalverticesarev1,v3,v4,
v5,v6,v9.Theseare6(=71= p1)innumber.
9.3.7Definition:
Letv beavertexinabinarytree.Thenv issaidtobeatlevel I ifv isata
distanceofI fromtheroot.
9.3.8 Example:
i) A13vertex,4levelbinarytreewasgiveninFig.9.3.8.
level1
level4
level0
level2
level3
Fig.9.3.8
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:202
Here the number of vertices at levels 0, 1, 2, 3, 4 are 1, 2, 2, 4 and
4respectively.
9.3.9Definition:
Thesumofpath lengthsfromthe root toallpendentvertices iscalled the
pathlength(or) externalpathlengthofatree.
9.3.10Example:
i) ThepathlengthofthebinarytreegiveninFig.9.3.8is:
1+3+3+4+4+4+4=23.
ii) IntheFigures9.3.10A and B,therearetwo11vertexbinarytrees.
Thepathlengthofgraph(fig.9.3.10A):2+2+3+3+3+3=16.
Thepathlengthofgraph(fig.9.3.10B):1+2+3+4+5+5=20.
level5
level0
level1
level2
level4
level3
Fig9.3.10B
level 1
level 0
level 2
level 3
Fig9.3.10A
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:203
9.3.11Searchprocedures
Eachvertexofabinarytreerepresentsatestwithtwopossibleoutcomes.
Westartattheroot.Theoutcomeofthetestattherootsendsustooneof
thetwoverticesat thenext level,wherefurthertestsaremadeandsoon.
Reachingaspecifiedpendentvertex(thatvertexwhichrepresentsthegoal
ofthesearch),terminatesthesearch.
Forsuchsearchprocedures,itisoftenimportanttoconstructabinarytreein
which,foragivennumberofvertices n,thevertexfrothiestfromtherootin
asclosetotherootaspossible.
i) Therecanbeonlyonevertex(theroot)atlevel0.Numberofvertices
atleveloneisatmost2.Numberofverticesatleveltwoisatmost22
andsoon.So themaximumnumberofverticespossible inak level
binarytreeis20 +21 +22 +...+2k.
So n 20 +21 +22 +...+2k
ii) Themaximumnumberamongthelevelsoftheverticesinabinarytree
iscalledheightofthetree.Soheight=max{levelofavertex v /
v V}.
Thisheightisdenotedby lmax.
iii) Toconstructabinarytreeforagiven n suchthatthefarthestvertex
isasfaraspossiblefromtheroot,wemusthaveexactlytwoverticesat
eachlevel,exceptatthe0level.Somaxlmax =2
1n- .
9.3.12AnApplication:(CokeMachineProblem)
Supposethat there isa.Themachine is tohaveasequenceof tests (for
example, it should be capable of identifying the coin that is put into the
machine).We suppose that five rupees coin, two rupees coin, one rupee
coinandfiftypaisecoincangothroughtheslot.Sothemachinecanidentify
only these four coins.Every coin put in, is tobe testedby themachine.
Each test got the effect of partitioning the coins into two complementary
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:204
sets.[Supposeacoinisputintothemachine.Itshouldtestwhetherthecoin
isfiverupeecoin.Ifitisnotafiverupeescoin,thenitshouldtestwhetheritis
atworupeescoinandsoon].Wesupposethetimetakenforeachtestis.
TestPattern1:Onetypeof testingpatternwasshowninGraph(i), given
inFig.9.3.12A.
Supposethestatisticaldatatellsthat
w1 =probabilityofputtingaRs 5coin=0.5
w2 =probabilityofputtingaRs 2coin=0.2
w3 =probabilityofputtingaRs 1coin=0.2
w4 =probabilityofputtingaRs 0.5coin=0.1
Now
)v(lw ii = )v(lw 11 + )v(lw 22 + )v(lw 33 + )v(lw 44 =(0.5)(1) +(0.2)(2)+(0.2)(3)+(0.1)(4)=1.9
Soexpectedtimetobetakenbythemachinefortestingonecoinis1.9t.
Thus if themachinefollows (for its testingpattern) thebinary treegiven in
Graph(a),thentheexpectedtimefortestingonecoinisequalto1.9t.
Test Pattern2: Another type of testing pattern was given in the
Fig.9.3.12B.
Rs0.5coin
Rs1coin
Rs5coin
v30.2
v1
v2
v40.1
0.2
0.5
notRs1coin
notRs0.5coin
notRs2coin
notRs5coin
Fig9.3.12A
Rs2coin
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:205
)v(lw ii = )v(lw 11 + )v(lw 22 + )v(lw 33 + )v(lw 44 =(0.5)(2)+(0.2)(2)+(0.2)(2)+(0.1)(2)=2.0
Sohere,theexpectedtimetobetakenbythemachinefortestingonecoin
is2t.
Thus if themachinefollows (for its testingpattern) thebinary treegiven in
graph9.3.12Bthentheexpectedtimefortestingonecoinis2t.
9.3.13Definition:
Agraph G inwhicheveryvertexisassignedauniquenameorlabel(that
is,notwoverticeshavethesamelabel)iscalledalabeledgraph.Otherwise
issaidtobeanunlabeledgraph.
9.3.14Example:
Ifn =4,thenthereare16trees,shownbelow.
TakethevertexsetV ={A,B,C,D}.
v1 v2 v3 v40.10.2
0.20.5
Rs5or Rs2
Rs5 Rs2Rs1
Rs0.50
Rs1or Rs0.50
Fig9.3.12B
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:206
Thefollowingarethe16treesoffourlabeledvertices
B
C
A
D
A
DC
BA
C D
B
C
BA
D
A B
DC DC
BA
A B
C D
A B
C D
A
C
B
D
B
D
A
C
A B
C D
A B
C DA B
C D
A B
CD
A B
C D
A B
CD
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:207
Observations:
i) Whenwecountthenumberofdifferentgraphs,thedistinctionbetween
labeledandunlabeledgraphsisimportant.
ii) ConsiderthegraphsinExample9.3.14,the5th,6th,7th and8th,are
counted as four different trees (even through they are isomorphic),
becausetheyarelabeled.Ifthereisnodistinctionbetween A,B,C,
D,thenthesefourtreescountedasone.
iii) A careful inspectionof the 16 graphswill reveal that thenumberof
unlabeledtreeswithfourvertices(nodistinctionmadebetween A, B,
C, D),istwo.Thesetwographswere.
9.3.15CayleysTheorem:
Thenumberoflabeledtreeswith n vertices(n 2)is n(n2).
9.3.16 Example:Part(i):Suppose thegiven tree is T1 (Fig. 9.3.16A). a1 = thependentvertexwithsmallestlabel.So a1 isthevertex2.Now b1 =1.Afterremoving a1 andtheedge(a1,b1), intheremaininggraph,a2 = thependentvertexwithsmallestindex=4.
a1
1
2
6
5
3
79
4
8
Fig.9.3.16A
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:208
Now b2 =1. a3=1, b3=3, a4 =3, b4 =5, a5 =6, b5 =5, a6 =
7, b6=5, a7=5, b7=9.
Thereforewehavethesequence(b1, b2,b3, b4,b5, b6,b7)=(1,1,3,5,5,5,9).
Part(ii): (converseofpart(i)):wehavetoconstructatreewith n =9vertices.
Consider1,2,3,4,5,6,7,8,9.........(i)
Given(n2)tupleis(1,1,3,5,5,5,9).......(ii)
Observethesequencein (ii). First join1and3, 3and5, 5and9.
Thenweget thegraphgiven inFig.9.3.16B. Nowthe leastnumber in (i)
whichisnotin(ii),is2.Sowejoin2and1.Nextleastin(i)whichisnotin(ii)
is4.Sowejoin4and1.Cancel3in(i)and3in(ii).Alsocancel5in(i)
and5 in (ii) (in (ii), cancelingofonlyone 5 isallowed).Thenext least
whichisnotin(ii)is6.Sowejoin5and6.Thenextleastwhichisnotin(ii)
is 7. So we join 7 and 5. The next least which is not in (ii) is 8. The
remainingnumberavailablein(ii)is9.Sowejoin8and9.
13
5
9
Fig9.3.16B
8
1
2
6
5
3
7
9
4
Fig9.3.16C
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:209
Nowwewillstudythetreeasasubgraphofanothergraph.Agivengraph
mayhavenumeroussubgraphs.If e isthenumberofedgesin G,then
there are 2e distinct subgraphs are possible. Obviously some of these
subgraphs will be trees. Out of these trees we particularly interested in
certaintypeoftrees,calledspanningtrees.
9.4SpanningTrees
9.4.1Definition:
Atree T issaidtobeaspanningtreeofaconnectedgraph G if T isa
subgraphof G and T containsalltheverticesof G.
9.4.2 Example: Consider the graph G given in Fig. 9.4.2 A. Graph T
(giveninFig.9.4.2B)isaspanningtreeof G.
v3
v1
v4v2
v5
v6
v7b2
b3
b1
b6
b4
c5
c6
c8
c7
c1
b5
c2
c3
c4
Fig.9.4.2AGraphG
v7
v1
v2
v3v4
v5
v6
Fig.9.4.3BGraphT
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:210
Observations:
i) Spanning treesare the largest (with themaximumnumberofedges)
treesamongalltreesinG.Spanningtreeisalsocalledamaximaltree
subgraphormaximaltreeof G.
ii) Spanningisdefinedonlyforaconnectedgraph(sinceatreeisalways
connected).
iii) Eachcomponentofadisconnectedgraph,doeshaveaspanningtree.
Thus a disconnected graph with k components contains a spanning
forestconsistingof k spanningtrees.
9.4.3Theorem:
Everyconnectedgraphhasatleastonespanningtree.
9.4.4Definition:
i) Anedgeinaspanningtree T iscalledabranchof T.
ii) Anedgeof G that isnot inagivenspanningtree T iscalleda
chord.Inelectricalengineering,chordsometimesreferredtoastieora
link.
iii) Let T beanyspanningtreeofaconnectedgraph G,and T1 isthe
complementof T in G.Theneachedgein T iscalledabranch(with
respectto T),andthesetofalledgesin T iscalledthebranchset.
Eachedgein T1 iscalledachord(withrespectto T),andthesetof
edges in T1 is called thechord set (or)Tieset. T1 is calledas the
cotree.WemaywriteT insteadof T1.
Observation:
i) Branchesandchordsaredefinedonlywithrespecttoagivenspanning
tree.
ii) Anedgethatisabranchwithrespecttoonespanningtree T1 (of G)
maybeachordwithrespecttoanotherspanningtree T2.
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:211
9.4.5Theorem:
Withrespecttoanyofitsspanningtrees,aconnectedgraphofnvertices
andeedgeshasn1treebranchesand en+1chords.
Proof:LetG beanyconnectedgraphonnverticesand e edges.Let
T beanyspanningtreein G. Sinceeveryspanningtreeof G contains
allverticesof G,wehavethat|V(T)|= n andso|E(T)|=|V(T)|1= n
1.Sinceeveryedgeofaspanningtree T iscalledabranchofT,wehave
that Gcontains n1branches.SincethenumberofedgesinG is e,we
havethatthenumberofchordsof Tis e(n1)=en+1.
9.4.6Example:
Thereisaformconsistingofsixwalledplotsoflandasshowninthefigand
theseplotsarefullofwater.Wefindtheminimumnumberofwallsaretobe
brokensothatallthewatercanbedrainedout.
Consider the wall joints as vertices, and walls as edges. Then we can
consider itasagraph. Inthisgraphthenumberofvertices is n=10,and
thenumberofedgesis e=15.
Fig.9.4.6
If thereexistsacircuit, thenthewater inside thecircuitcannotbedrained
out.Sowehavetoremoveminimumnumberofedgessothatthegraphdo
not contain circuits. Tohave this, weshouldhave a spanning treewith
(n1)edges.Hencewehavetobreak e(n1)= en+1=1510
+1=6edges(walls)sothatallthewatercanbedrainedout.
If we add an edge between any two vertices of a tree, then a circuit is
created. This is because, therealreadyexistsonepathbetweenany two
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:212
verticesofa tree, addinganedge inbetween, createsanadditionalpath,
andhenceacircuit.Theconceptofafundamentalcircuithasanenormous
significanceinelectricalnetworkanalysis.
9.4.7Definition:
Let T beany spanning treeof a connectedgraph G.Addinganyone
chordto T willcreateexactlyonecircuit.Suchacircuitformedbyaddinga
chordtoaspanningtree,iscalledafundamentalcircuit.
9.4.8 Example: Consider the graph G (given in Fig. 9.4.8A), and its
spanningtree T(giveninFig.9.4.8B)of G.Now,ifweaddthechord c1
to T,wegetacircuitb1b2b3b5c1whichiscalledasfundamentalcircuit
(giveninFig.9.4.8C).
9.4.9Problem:AconnectedgraphG isatree ifandonly if addingan
edgebetweenanytwoverticesin G createsexactlyonecircuit.
Prof:SupposeGisatrue.Supposeweaddanewedge e= uv between
twovertices u and v in G.Since G isatree, G containsapathfrom u
and v.Byjoiningthisnewedge,therecreatesexactlyonecircuit.
c7c5
c6
c8
c4c3
c1
b2
b1
b4
b5b3b6
c2
Fig9.4.8AGraphG
b1
b2
b3
b4
b6b5
Fig.9.4.8BSpanningtreeT
c1b1
b2
b3
b4
b6b5
Fig.9.4.8CFundamentalcircuitF
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:213
Converse: Supposetheconversehypothesis.SupposeGcontainsacircuit:
v1e1v2e2env1.Byaddingnewedge e1= v1v2 ,wegettwocircuits v1e1
v2e1v1 and v1e1v2e2v3env1, acontradiction.So G containsnocircuits.
NowweshowthatGisconnected.Let u,v betwoverticesinG.Adda
newedge e*= uv toG.Thenbyconversehypothesis,therecreatesa
circuit.Supposethecircuitis ue*e1v1e2v2.eku.Now ve1v1e2v2ekuis
apathinbetweenv and u.Thisshowsthatthegraph G isconnected.
Hence G isatree.
9.4.10Problem:
ForatreeG isatree,byaddinganewedgebetweenanytwoverticesin G
creates,exactlyonefundamentalcircuit.
9.5AlgorithmsforSpanningTrees
9.5.1Definition:
i) AgraphG issaidtobeaweightedgraphifalltheedgese ofG were
assignedbyacorrespondingrealnumber w(e)(readastheweightofe).
ii) Let T beanyspanningtreeofaconnectedgraph G.thentheweight
of T,thatis, w(T)isdefinedasthesumofweightsofallbranches
inT.
iii) Aspanningtreewiththesmallestweightinaweightedgraphiscalleda
shortestspanningtree(or)minimalspanningtree(or)shortestdistance
spanningtree.
Observation:
i) Different spanning treesofG mayhavedifferentweights.Amongall
the spanning trees of G, one with the smallestweight is of practical
significance.
ii) Let G beagraphon n verticesinwhicheveryedgehasaunitweight.
Thenallthespanningtreeshavethesameweightof(n1)units.
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:214
9.5.2AnApplication:
i) Suppose that we are to connect n cities v1, v2,, vn through a
networkofroads.
ii) ThecostCij ofbuildingadirectroadbetween vi and vj isgivenfor
pairsofcities vi and vj whereroadscanbebuilt.(Notethatthere
maybepairsofcitiesbetweenwhichnodirectroadcanbebuilt).
iii) Nowtheproblemis:Tofindtheleastexpensivenetworkthatconnects
all n cities together. That is, to find a shortest spanning tree in a
connectedweightedgraphofnvertices.
iv) Heretheconnectednetworkmustbeatree.Otherwise,wecanalways
removesomeedgesandget a connectedgraphwith smallerweight.
Thus the problem of connecting n cities with a least expensive
network is the problem of finding a shortest spanning tree in a
connectedweightedgraphofnvertices.
9.5.3Problem: Let T bespanning tree (ofaweightedconnectedgraph
G).Thenthefollowingconditionsareequivalent:
i) T isashortestspanningtree(of G)and
ii) Thereexistsnospanningtree(of G)atadistanceonefrom T whose
weightissmallerthanthatof T.
9.5.4KruskalAlgorithm:(findingshortestspanningtree)
Step(i):ListalltheedgesofGinorderofnondecreasingweight.Nowwe
selectanedgee1ofGsuchthat w(e1)isassmallaspossibleande1isnot
aloop.
Step(ii):Selectnextsmallestedgefrom thesetofall remainingedgesof
G such that the selectededgedonot formacircuitwith theedges that
havealreadybeenchosen.
Step(iii):Wecontinuethisprocessof takingsmallestedgesamongthose
notalreadychosen,providednocircuitisformedwiththose,thathavebeen
chosenalready.
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:215
[If edges e1, e2, , ei have been chosen, then chose ei+1 from E
{e1,e2,,ei}insuchwaythatgraphwith{e1,e2,,ei+1}isacyclicand
w(ei+1)isassmallaspossible].
Step(iv):Ifagraph G hasnvertices,thenwewillstopthisprocess
afterchoosing n1edges.Theseedgesformasubgraph T,whichisnot
cyclic.(Thus T isashortestspanningtreeof G).
9.5.5 Example:
ConsidertheconnectedweightedgraphG.Listing:
)1(AB , )1(AD , )2(BC , )2(CD , )3(AE , )3(FE , )3(AF , )4(EB ,
)4(AC , )4(ED , )5(FD .
Step(i):Consideraspanningsubgraphof G withoutedges.
Select theedgewithminimumweight. For thisgraph theedgeAB isof
minimumweight.
Add this edge e1 = AB to the spanning null graph. Then we get the
subgraphG1.
Step(ii):Selecttheedge e2 suchthat G1+e2 containsnocircuitsand e2
gotminimumweightamongsuchedges.Forthisgraph e2=AD.Nowadd
e2 = ADto G1.ThenwegetthesubgraphG2.
Step(iii):Wecontinuethisprocess.Forthisexample,weadd e3 = BCto
G2 togetthesubgraphG3.
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:216
Nextweadd e4 =AE to G3 toget the subgraphG4. Nextweadd
e5 = EF toget the subgraphG5. Ifweaddanyedge to G5, weget a
circuit.Sotheprocessistobestoppedhere.
A
B
E
1F
12
Graph G5 or T
D C
33
F
A
B
E
1
12
SubgraphG4
DC
3
F
E
A
B
1
12
SubgraphG3
D CC
A
B
1
1 SubgraphG2
D
F
E
C
2
5 1
D
4
A
B
E
F
1
23 4
3
3
4
GraphG
A
B1
SubgraphG1
F
E
D
C
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:217
Thefinalgraph G5 isasubgraphof G andcontainsnocycles.Thus G5
isashortestspanningtreeofG.Write T = G5.Now w(T)=sumofthe
weightsofthebranchesin T =1+2+1+3+3= 10
9.5.6Prim'sAlgorithm:
Step(i):Chooseanyvertex v1 in G.
Step(ii):Chooseanedgee1=v1v2 of G suchthat v1 v2ande1has
the smallest weight among the edges of G incident with v1 . [For
convenience,wecanformatableindicatingtheweights].
Step(iii): Iftheedges e1,e2,,ei havebeenalreadychoseninvolving
endvertices v1,v2,,vi+1 ,chooseanedgeei+1,where ei+1=vjvk with
vj {v1,v2,,vi+1},and vk {v1,,vi+1}suchthat ei+1 hasthesmallest
weightamongtheedgesof G withpreciselyoneendin{v1,v2,,vi+1}.
Notethatafteraddingei+1 thegraphshouldbeacyclic.
Step(iv): The process will stop after choosing the n1 edges (otherwise,
repeatthestep(iii)).
9.5.7Illustration:Considertheconnectedweightedgraph G.Letusstart
with C.
5 1
D
4 2
A
C
B
E
F
1
23 4
33
4
GivengraphG GraphG1D
A
F
E
B
C
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:218
Step(i):Takethespanningnullsubgraph G0 of G.
Letuschoosev1=A.TheedgeAD isincidenton v1 andhasthesmallest
weightamongtheedgesincidentonv1=A.WriteG1 =(G0+AD)
Step(ii): InthisstepweselectDCandwriteG2=(G1+DC).
Step(iii): Weselect AB andwrite G3=(G2+ AB).
Step(iv):Weselect AF andwrite G4=(G3+AF).
Step(v):WeselectFEandwriteG5=(G4+FE).
Step(vi):Since G5 isaspanningtree,theprocessstopshere.
Write T = G5.
Hence,theshortestspanningtreeof G isG5=T.
Now w(T)=1+1+2+3+3=10.
A
B
E
1
F
1
2D
C
3
3
GraphG5=T
A
B1
F
1
2D
C
3
GraphG4
E
A
B1
1
2D
C
GraphG3
F
E
A
1
1
D
C
GraphG2
F
E
B
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:219
SelfAssessmentQuestions:
1. Drawtreeswith5vertices.
2. Findallspanningtreesofthegraph.
3. Findallspanningtreesofthefollowinggrpah.
4. The complete graph on n vertices Kn: has2 -nn different spanning
trees.GiveallthespanningtreesofK4.
5. Findaspanningtreeforeachofthefollowinggraphs
6. Whichconnectedsimplegraphshaveexactlyonespanningtree?
o oo
o
o
oo o
o o
(i)o
o
o
o o
o o
o o
(ii)
o
o
o
o
(iii)
o
o
o o
o
(iv)
o
o
ooo
o
o o
o
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:220
7. UsePrimsAlgorithmtofindaminimalspanningtreeforthefollowing
weightedgraph.
9.6Summary:
Thisunitdealtwithaspecialtypeofgraphsnamelytrees,whichareextensively
usedsearchproceduresanddesignofcomputeralgorithms.Thereaderwillbe
abletogetandideatofindthedifferentspanningtreesfromagivenconnected
graph. Different characterizations and properties of trees were given. Also
someapplicationsofbinarytreeswerediscussed.Spanningtreeplayavital
roleinmulticastingoverinternetprotocolnetworks.
9.7TerminalQuestions
1. Draw two different binary trees with five vertices having maximum
numberofleaves.
2. Drawagraphwiththegivenspecification.Incase,ifnotpossible,then
explainwhynosuchgraphsexists.
i) fullbinarytree,fiveinternalvertices
ii) fullbinarytree,fiveinternalvertices,seventerminalvertices
iii) fullbinarytree,twelvevertices
iv) fullbinarytree,ninevertices.
3. If T1 andT2 aretwospanningtreesinagraph,thenshowthat
i) Thenumberofedgesin T1 not in T2 isequaltothenumberof
edgesinT2 notin T1.(ii) d(T1,T2)= d(T2,T1).
4. LetN(g)=thenumberofedgesinagraph g.Then N(Ti Tj)=the
8
A
3
6
47
2
46
8 6
C
BE
D
o
o
o
o
o
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:221
numberofedgesinTi Tj ,and d(Ti,Tj)=Thedistancebetween Ti
and Tj.Showthat d(T1,T2)=21
N(T1 T2).
5. Considerthetableofairlinedistancesinmilesbetweensixoflargestcities
intheworld:London,Mexico,NewYork,Paris,PekingandTokyo.
L MC NY Pa Pe T
L 5558 3469 214 5074 5959
MC 2090 5725 7753 7035
NY 3636 6844 6757
Pa 5120 6053
Pe 1307
T
9.8Answers
SelfAssessmentQuestions
1.
2. The given graph has four vertices and so each spanning tree must
have41=3edges.Theyare
o
o
o
o
o
oo
o
o
o
o
o
o
o
o
o o
o
o
o
o o o o o o
o
o o
o
o
o
o
oo o oo
o o
ooo oo o
o
L
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:222
4. K4has244 - =16differentspanningtrees.Eachhavingthreeedges.
5.
6. Tree.
7. ChooseedgesAE,AC,DC,AB.
3.o o
o
o
oo o o o
o o o oo
oo o
o
(i) o
oo
o
o
o
o
o
o
(ii) o
oo o
(iii) o
o
o
o
o
(iv)
o
o o
o
o
oo
o
o
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:223
TerminalQuestions
1.
2.
ii) Not possible, since any full binary tree with five internal vertices
havesixterminalvertices,butnotseven.
iii) No,afullbinarytreehas2k+1verticeswherekisthenumberof
internalverticesbut2k+1isodd.
iv)
3. i) Let T1,T2 betwospanningtrees.Now|E(T1)|= n1=|E(T2)|.
Suppose T1 contains m edgeswhicharenotin T2.Nowthe
numberofedgesin T2 notin T1 is
(n1)[(n1)m]= m.followsfrom(i).
(i)
b
c
a
e
f g
j k
o
o
oo
o
o
o
d
h io o
o o
o
oo
o
oo
o
oo
o
o o
o o o
o
oo
o
ModernApplicationsusingDiscreteMathematicalStructures Unit9
SikkimManipalUniversity PageNo:224
4. N(T1 T2)=numberofedgesinT1 T2 =(numberofedgesinT1but
notinT2)+(numberofedgesinT1butnotinT2)= d(T1,T2)+d(T2,
T1)=2d(T1,T2) d(T1,T2)=21
N(T1 T2)
5.
214
2090
3469
5074
1307
MC
NY
T
L
Pa
Pe
FigB Shortest spanning tree
5725
6053
7753
6757
50743469
5120 3636
5558
2090
5959
1307
T
Pe
MC
NY
Pa
7035
6844
214
Fig.A
Recommended