distributed systems minimum spanning trees · minimum spanning trees rik sarkar university of...

28
Distributed Systems Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016

Upload: others

Post on 04-Jul-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

DistributedSystems

MinimumspanningtreesRikSarkar

UniversityofEdinburgh

Fall2016

Page 2: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Minimumspanningtrees

•  DefiniBon(inanundirectedgraph):– Aspanningtreethathasthesmallestpossibletotalweightofedges

DistributedSystems,Edinburgh,2016 2

Ref:Wiki

Page 3: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Minimumspanningtrees

•  Usefulinbroadcast:– UsingafloodontheMSThasthesmallestpossiblecostonthenetwork

DistributedSystems,Edinburgh,2016 3

Page 4: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Minimumspanningtrees

•  UsefulinpointtopointrouBng:– Minimizesthemaxweightonthepathbetweenanytwonodes

DistributedSystems,Edinburgh,2016 4

Page 5: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Property:CutopBmality

•  EveryedgeoftheMSTparBBonsthegraphintotwodisjointsets(createsacut)– EachsetisindividuallyconnectedbyMSTedges

DistributedSystems,Edinburgh,2016 5

Page 6: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Property:CutopBmality

•  EveryedgeoftheMSTparBBonsthegraphintotwodisjointsets(createsacut)– EachsetisindividuallyconnectedbyMSTedges

•  NoedgeacrossthecutcanhaveasmallerweightthantheMSTedge

DistributedSystems,Edinburgh,2016 6

Page 7: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Property:CutopBmality•  EveryedgeoftheMSTparBBons

thegraphintotwodisjointsets(createsacut)–  EachsetisindividuallyconnectedbyMSTedges

•  NoedgeacrossthecutcanhaveasmallerweightthantheMSTedge

•  Proof:Iftherewassuchanedge,thenwecanswapitforthecurrentedgeandgetatreeofsmallertotalweight

DistributedSystems,Edinburgh,2016 7

Page 8: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Property:CycleopBmality

•  Everynon-MSTedgewhenaddedtoMSTsetcreatesacycle

•  Itmusthavemaxweightinthecycle

DistributedSystems,Edinburgh,2016 8

Page 9: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

MST:Notnecessarilyunique

•  Why?

DistributedSystems,Edinburgh,2016 9

Page 10: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

MST:Notnecessarilyunique

•  Assume:– Alledgeweightsareunique

DistributedSystems,Edinburgh,2016 10

Page 11: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Prim’sAlgorithm

•  IniBalizeP={x};Q=E–  (xisanyvertexinV)

•  WhileP≠V– Selectedge(u,v)inthecut(P,V\P)

•  (attheboundaryofP)• Withsmallestweight

– AddvtoP

DistributedSystems,Edinburgh,2016 11

Page 12: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Prim’sAlgorithm

•  IfwesearchfortheminweightedgeeachBme:O(n2)

DistributedSystems,Edinburgh,2016 12

Page 13: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Prim’sAlgorithm

•  Ifweuseheaps:– O(mlogn)[binaryheap]– O(m+nlogn)[Fibonacciheap]

DistributedSystems,Edinburgh,2016 13

Page 14: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Prim’sAlgorithm

•  CanwehaveanefficientdistributedimplementaBon?

DistributedSystems,Edinburgh,2016 14

Page 15: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Prim’sAlgorithm

•  Ineveryround,weneedtofindthelowestweightboundaryedge.

•  Useaconvergecast(aggregaBontreebased)–  Ineveryround– Fornrounds

DistributedSystems,Edinburgh,2016 15

Page 16: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Prim’sAlgorithm

•  WhatistherunningBme?•  WhatiscommunicaBoncomplexity?

DistributedSystems,Edinburgh,2016 16

Page 17: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Prim’sAlgorithm

•  Theweakness:•  DoesnotusethedistributedcomputaBon•  Treespreadsfromonepoint,restofnetworkisidle

DistributedSystems,Edinburgh,2016 17

Page 18: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Kruskal’salgorithm

•  Workswithaforest:AcollecBonoftrees•  IniBally:eachnodeisitsowntree•  Sortalledgesbyweight•  Foreachtree,– Findtheleastweightboundaryedge– Addittothesetofedges:mergestwotreesintoone

– RepeatunBlonly1treelem

DistributedSystems,Edinburgh,2016 18

Page 19: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Kruskal’salgorithm•  Theproblemstep:–  “Findtheleastweightboundaryedge”

•  Howdoyouknowwhichistheboundaryedge?•  Maintainidforeachtree(storethisateverynode)

•  Easytocheckifend-pointbelongtodifferenttrees

•  Whenmergingtrees,updatetheidofoneofthetrees–  Expensive,sinceallnodesinthetreehavetobeupdated

DistributedSystems,Edinburgh,2016 19

Page 20: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Kruskal’salgorithm

•  Whenmergingtrees,updatetheidofoneofthetrees– Expensive,sinceallnodesinthetreehavetobeupdated

•  SoluBon:alwaysupdatetheidofthesmallertree(theonewithfewernodes)

•  ThecostforallidupdatesisO(nlogn)

DistributedSystems,Edinburgh,2016 20

Page 21: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

Kruskal’salgorithm•  Claim:ThecostforallidupdatesisO(nlogn)•  Proof:(byinducBononlevels)–  Supposethefinallistofnelementswasobtainedbymergingtwolistsofhelementsandn-helementsinthepreviouslevel

–  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

Page 22: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

GHSDistributedMSTAlgorithm

•  ByGallagher,HumbletandSpira•  Eachnodeknowsitsownedgesandweights

DistributedSystems,Edinburgh,2016 22

Ref:NL

Page 23: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

GHSDistributedMSTAlgorithm

•  Worksinlevels•  Inlevel0eachnodeisitsowntree•  Eachtreehasaleader(leaderid==treeid)•  Ateachlevelk:– AllLeadersexecuteaconvergecasttofindtheminweightboundaryedgeinitstree

–  Itthenbroadcaststhisinitstreesothatthenodethathastheedgeknows

–  Thisnodeinformsthenodeontheotherside,whichinformsitsownleader

DistributedSystems,Edinburgh,2016 23

Page 24: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

GHSDistributedMSTAlgorithm•  ObservaBon1:

–  WearepossiblymergingmorethantwotreesatthesameBme–  Problem:whoistheleaderofthenewtree?

•  ObservaBon2:–  Themergedtreeisatreeoftrees:itcannothaveacycle–  WecanassignadirecBontoeachedgeandeachnode(tree)hasanoutgoingedge

–  Theremustbeapairofnodes(trees)thatselecteach-other(otherwisethemergedtreeisinfinite)

–  Weselecttheedgeusedtomergethesetwotrees•  SelectthenodewithhigherIDtobeleader

–  TheleaderthenbroadcastsamessageupdaBngleaderidatallnodes.

DistributedSystems,Edinburgh,2016 24

Page 25: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

GHSDistributedMSTAlgorithm

•  Complexity:•  Thenumberofnodesateachlevelktreeisatleast2k

•  SincestarBngatsize1,thenumberofnodesinthesmallesttreeatleastdoubleseverylevel

•  Therefore,thereareatmostO(logn)levels

DistributedSystems,Edinburgh,2016 25

Page 26: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

GHSDistributedMSTAlgorithm

•  Complexity:•  Ateachlevel,ateachtree,weuseconstantnumberofbroadcastsandconvergecasts

•  EachlevelcostsO(n)Bme•  Totalcosts:O(nlogn)Bme

DistributedSystems,Edinburgh,2016 26

Page 27: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

GHSDistributedMSTAlgorithm

•  Complexity:•  Ateachlevel,ateachtree,weuseconstantnumberofbroadcastsandconvergecasts

•  EachlevelcostsO(n)messages•  Totalcosts:O(nlogn+|E|)messages

DistributedSystems,Edinburgh,2016 27

Page 28: Distributed Systems Minimum spanning trees · Minimum spanning trees Rik Sarkar University of Edinburgh Fall 2016 Minimum spanning trees • DefiniBon (in an undirected graph): –

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