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

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

Author: others

Post on 04-Jul-2020

0 views

Category:

Documents


0 download

Embed Size (px)

TRANSCRIPT

  • DistributedSystems

    MinimumspanningtreesRikSarkar

    UniversityofEdinburgh

    Fall2016

  • Minimumspanningtrees

    •  DefiniBon(inanundirectedgraph):– Aspanningtreethathasthesmallestpossibletotalweightofedges

    DistributedSystems,Edinburgh,2016 2

    Ref:Wiki

  • Minimumspanningtrees

    •  Usefulinbroadcast:– UsingafloodontheMSThasthesmallestpossiblecostonthenetwork

    DistributedSystems,Edinburgh,2016 3

  • Minimumspanningtrees

    •  UsefulinpointtopointrouBng:– Minimizesthemaxweightonthepathbetweenanytwonodes

    DistributedSystems,Edinburgh,2016 4

  • Property:CutopBmality

    •  EveryedgeoftheMSTparBBonsthegraphintotwodisjointsets(createsacut)– EachsetisindividuallyconnectedbyMSTedges

    DistributedSystems,Edinburgh,2016 5

  • Property:CutopBmality

    •  EveryedgeoftheMSTparBBonsthegraphintotwodisjointsets(createsacut)– EachsetisindividuallyconnectedbyMSTedges

    •  NoedgeacrossthecutcanhaveasmallerweightthantheMSTedge

    DistributedSystems,Edinburgh,2016 6

  • Property:CutopBmality•  EveryedgeoftheMSTparBBons

    thegraphintotwodisjointsets(createsacut)–  EachsetisindividuallyconnectedbyMSTedges

    •  NoedgeacrossthecutcanhaveasmallerweightthantheMSTedge

    •  Proof:Iftherewassuchanedge,thenwecanswapitforthecurrentedgeandgetatreeofsmallertotalweight

    DistributedSystems,Edinburgh,2016 7

  • Property:CycleopBmality

    •  Everynon-MSTedgewhenaddedtoMSTsetcreatesacycle

    •  Itmusthavemaxweightinthecycle

    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

    •  IfwesearchfortheminweightedgeeachBme:O(n2)

    DistributedSystems,Edinburgh,2016 12

  • Prim’sAlgorithm

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

    DistributedSystems,Edinburgh,2016 13

  • Prim’sAlgorithm

    •  CanwehaveanefficientdistributedimplementaBon?

    DistributedSystems,Edinburgh,2016 14

  • Prim’sAlgorithm

    •  Ineveryround,weneedtofindthelowestweightboundaryedge.

    •  Useaconvergecast(aggregaBontreebased)–  Ineveryround– Fornrounds

    DistributedSystems,Edinburgh,2016 15

  • Prim’sAlgorithm

    •  WhatistherunningBme?•  WhatiscommunicaBoncomplexity?

    DistributedSystems,Edinburgh,2016 16

  • Prim’sAlgorithm

    •  Theweakness:•  DoesnotusethedistributedcomputaBon•  Treespreadsfromonepoint,restofnetworkisidle

    DistributedSystems,Edinburgh,2016 17

  • Kruskal’salgorithm

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

    – RepeatunBlonly1treelem

    DistributedSystems,Edinburgh,2016 18

  • Kruskal’salgorithm•  Theproblemstep:–  “Findtheleastweightboundaryedge”

    •  Howdoyouknowwhichistheboundaryedge?•  Maintainidforeachtree(storethisateverynode)

    •  Easytocheckifend-pointbelongtodifferenttrees

    •  Whenmergingtrees,updatetheidofoneofthetrees–  Expensive,sinceallnodesinthetreehavetobeupdated

    DistributedSystems,Edinburgh,2016 19

  • Kruskal’salgorithm

    •  Whenmergingtrees,updatetheidofoneofthetrees– Expensive,sinceallnodesinthetreehavetobeupdated

    •  SoluBon:alwaysupdatetheidofthesmallertree(theonewithfewernodes)

    •  ThecostforallidupdatesisO(nlogn)

    DistributedSystems,Edinburgh,2016 20

  • 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

  • GHSDistributedMSTAlgorithm

    •  ByGallagher,HumbletandSpira•  Eachnodeknowsitsownedgesandweights

    DistributedSystems,Edinburgh,2016 22

    Ref:NL

  • GHSDistributedMSTAlgorithm

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

    –  Itthenbroadcaststhisinitstreesothatthenodethathastheedgeknows

    –  Thisnodeinformsthenodeontheotherside,whichinformsitsownleader

    DistributedSystems,Edinburgh,2016 23

  • GHSDistributedMSTAlgorithm•  ObservaBon1:

    –  WearepossiblymergingmorethantwotreesatthesameBme–  Problem:whoistheleaderofthenewtree?

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

    –  Theremustbeapairofnodes(trees)thatselecteach-other(otherwisethemergedtreeisinfinite)

    –  Weselecttheedgeusedtomergethesetwotrees•  SelectthenodewithhigherIDtobeleader

    –  TheleaderthenbroadcastsamessageupdaBngleaderidatallnodes.

    DistributedSystems,Edinburgh,2016 24

  • GHSDistributedMSTAlgorithm

    •  Complexity:•  Thenumberofnodesateachlevelktreeisatleast2k

    •  SincestarBngatsize1,thenumberofnodesinthesmallesttreeatleastdoubleseverylevel

    •  Therefore,thereareatmostO(logn)levels

    DistributedSystems,Edinburgh,2016 25

  • GHSDistributedMSTAlgorithm

    •  Complexity:•  Ateachlevel,ateachtree,weuseconstantnumberofbroadcastsandconvergecasts

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

    DistributedSystems,Edinburgh,2016 26

  • GHSDistributedMSTAlgorithm

    •  Complexity:•  Ateachlevel,ateachtree,weuseconstantnumberofbroadcastsandconvergecasts

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

    DistributedSystems,Edinburgh,2016 27

  • DistributedMSTAlgorithm

    •  Non-uniqueedgeweights•  Ifedgeshaveduplicateweights•  Wemakethemunique:– Byensuringthatforanytwoedgeseande’– Eitherwt(e)<wt(e’)orwt(e’)