Minimum spanning tree. - University of Edinburgh

DistributedSystems
Minimumspanningtrees
RikSarkar
UniversityofEdinburgh
Fall2016
Minimumspanningtrees
•  DefiniBon(inanundirectedgraph):
Ref:Wiki
–  Aspanningtreethathasthesmallestpossible
totalweightofedges
DistributedSystems,Edinburgh,2016
2
Minimumspanningtrees
•  Usefulinbroadcast:
–  UsingafloodontheMSThasthesmallestpossible
costonthenetwork
DistributedSystems,Edinburgh,2016
3
Minimumspanningtrees
•  UsefulinpointtopointrouBng:
–  Minimizesthemaxweightonthepathbetween
anytwonodes
DistributedSystems,Edinburgh,2016
4
Property:CutopBmality
•  EveryedgeoftheMST
parBBonsthegraphinto
twodisjointsets(createsa
cut)
–  Eachsetisindividually
connectedbyMSTedges
DistributedSystems,Edinburgh,2016
5
Property:CutopBmality
•  EveryedgeoftheMST
parBBonsthegraphinto
twodisjointsets(createsa
cut)
–  Eachsetisindividually
connectedbyMSTedges
•  Noedgeacrossthecutcan
haveasmallerweightthan
theMSTedge
DistributedSystems,Edinburgh,2016
6
Property:CutopBmality
•  EveryedgeoftheMSTparBBons
thegraphintotwodisjointsets
(createsacut)
–  Eachsetisindividuallyconnectedby
MSTedges
•  Noedgeacrossthecutcanhavea
smallerweightthantheMSTedge
•  Proof:Iftherewassuchanedge,
thenwecanswapitforthecurrent
edgeandgetatreeofsmallertotal
weight
DistributedSystems,Edinburgh,2016
7
Property:CycleopBmality
•  Everynon-MSTedge
whenaddedtoMSTset
createsacycle
•  Itmusthavemaxweight
inthecycle
DistributedSystems,Edinburgh,2016
8
MST:Notnecessarilyunique
•  Why?
DistributedSystems,Edinburgh,2016
9
MST:Notnecessarilyunique
•  Assume:
–  Alledgeweightsareunique
DistributedSystems,Edinburgh,2016
10
Prim’sAlgorithm
•  IniBalizeP={x};Q=E
–  (xisanyvertexinV)
•  WhileP≠V
–  Selectedge(u,v)inthecut(P,V\P)
•  (attheboundaryofP)
•  Withsmallestweight
–  AddvtoP
DistributedSystems,Edinburgh,2016
11
Prim’sAlgorithm
•  Ifwesearchfortheminweightedgeeach
Bme:O(n2)
DistributedSystems,Edinburgh,2016
12
Prim’sAlgorithm
•  Ifweuseheaps:
–  O(mlogn)[binaryheap]
–  O(m+nlogn)[Fibonacciheap]
DistributedSystems,Edinburgh,2016
13
Prim’sAlgorithm
•  Canwehaveanefficientdistributed
implementaBon?
DistributedSystems,Edinburgh,2016
14
Prim’sAlgorithm
•  Ineveryround,weneedtofindthelowest
weightboundaryedge.
•  Useaconvergecast(aggregaBontreebased)
–  Ineveryround
–  Fornrounds
DistributedSystems,Edinburgh,2016
15
Prim’sAlgorithm
•  WhatistherunningBme?
•  WhatiscommunicaBoncomplexity?
DistributedSystems,Edinburgh,2016
16
Prim’sAlgorithm
•  Theweakness:
•  DoesnotusethedistributedcomputaBon
•  Treespreadsfromonepoint,restofnetwork
isidle
DistributedSystems,Edinburgh,2016
17
Kruskal’salgorithm
• 
• 
• 
• 
Workswithaforest:AcollecBonoftrees
IniBally:eachnodeisitsowntree
Sortalledgesbyweight
Foreachtree,
–  Findtheleastweightboundaryedge
–  Addittothesetofedges:mergestwotreesinto
one
–  RepeatunBlonly1treelem
DistributedSystems,Edinburgh,2016
18
Kruskal’salgorithm
•  Theproblemstep:
–  “Findtheleastweightboundaryedge”
•  Howdoyouknowwhichistheboundaryedge?
•  Maintainidforeachtree(storethisatevery
node)
•  Easytocheckifend-pointbelongtodifferent
trees
•  Whenmergingtrees,updatetheidofoneofthe
trees
–  Expensive,sinceallnodesinthetreehavetobe
updated
DistributedSystems,Edinburgh,2016
19
Kruskal’salgorithm
•  Whenmergingtrees,updatetheidofoneof
thetrees
–  Expensive,sinceallnodesinthetreehavetobe
updated
•  SoluBon:alwaysupdatetheidofthesmaller
tree(theonewithfewernodes)
•  ThecostforallidupdatesisO(nlogn)
DistributedSystems,Edinburgh,2016
20
Kruskal’salgorithm
•  Claim:ThecostforallidupdatesisO(nlogn)
•  Proof:(byinducBononlevels)
–  Supposethefinallistofnelementswasobtainedby
mergingtwolistsofhelementsandn-helementsinthe
previouslevel
–  Andh≤n/2
–  ThencostofcreaBngfinallistis(forsomeconstp):
• 
• 
• 
• 
• 
CostforcreaBngtwolists≤phlgh+p(n-h)lg(n-h)
CostforupdaBnglabels≤ph
Total≤phlgh+p(n-h)lg(n-h)+ph
Total≤ph(lg(n/2)+1)+p(n-h)lg(n-h)
≤pnlgn
•  Note:KruskalalsoneedsBmetosorttheedgesiniBally
DistributedSystems,Edinburgh,2016
21
GHSDistributedMSTAlgorithm
Ref:NL
•  ByGallagher,HumbletandSpira
•  Eachnodeknowsitsownedgesandweights
DistributedSystems,Edinburgh,2016
22
GHSDistributedMSTAlgorithm
• 
• 
• 
• 
Worksinlevels
Inlevel0eachnodeisitsowntree
Eachtreehasaleader(leaderid==treeid)
Ateachlevelk:
–  AllLeadersexecuteaconvergecasttofindthemin
weightboundaryedgeinitstree
–  Itthenbroadcaststhisinitstreesothatthenodethat
hastheedgeknows
–  Thisnodeinformsthenodeontheotherside,which
informsitsownleader
DistributedSystems,Edinburgh,2016
23
GHSDistributedMSTAlgorithm
•  ObservaBon1:
–  WearepossiblymergingmorethantwotreesatthesameBme
–  Problem:whoistheleaderofthenewtree?
•  ObservaBon2:
–  Themergedtreeisatreeoftrees:itcannothaveacycle
–  WecanassignadirecBontoeachedgeandeachnode(tree)has
anoutgoingedge
–  Theremustbeapairofnodes(trees)thatselecteach-other
(otherwisethemergedtreeisinfinite)
–  Weselecttheedgeusedtomergethesetwotrees
•  SelectthenodewithhigherIDtobeleader
–  TheleaderthenbroadcastsamessageupdaBngleaderidatall
nodes.
DistributedSystems,Edinburgh,2016
24
GHSDistributedMSTAlgorithm
•  Complexity:
•  Thenumberofnodesateachlevelktreeisat
least2k
•  SincestarBngatsize1,thenumberofnodes
inthesmallesttreeatleastdoublesevery
level
•  Therefore,thereareatmostO(logn)levels
DistributedSystems,Edinburgh,2016
25
GHSDistributedMSTAlgorithm
•  Complexity:
•  Ateachlevel,ateachtree,weuseconstant
numberofbroadcastsandconvergecasts
•  EachlevelcostsO(n)Bme
•  Totalcosts:O(nlogn)Bme
DistributedSystems,Edinburgh,2016
26
GHSDistributedMSTAlgorithm
•  Complexity:
•  Ateachlevel,ateachtree,weuseconstant
numberofbroadcastsandconvergecasts
•  EachlevelcostsO(n)messages
•  Totalcosts:O(nlogn+|E|)messages
DistributedSystems,Edinburgh,2016
27
DistributedMSTAlgorithm
•  Non-uniqueedgeweights
•  Ifedgeshaveduplicateweights
•  Wemakethemunique:
–  Byensuringthatforanytwoedgeseande’
–  Eitherwt(e)<wt(e’)orwt(e’)<wt(e)
–  Byusingnodeids
–  Eg.If(u,v)and(u’,v’)havesameweight,wedefine
•  Ifu<u’thenwt(u,v)<wt(u’v’)
•  Elseifu==u’,andifv<v’thenwt(u,v)<wt(u’v’)
DistributedSystems,Edinburgh,2016
28