Download as pdf or txt
Download as pdf or txt
You are on page 1of 112

Algorithms in General

Synchronous Networks
沈卓炜
zwshen@seu edu cn
zwshen@seu.edu.cn
九龙湖校区计算机楼334房间 Tel:52090919
13390922952

2012年3月
General Synchronous Network
Assumptions
• Digraph G = (V,E):
– V = set of processes
– E = set of communication channels
– di t
distance(i,j)
(i j) = shortest
h t t distance
di t from
f i to
t j
– diam= max distance(i,j) for all i,j
– Assume: Strongly connected (diam is finite),
finite) UIDs
• Set M of messages
• Processes communicate only over digraph edges.
• Generally don’t know the entire network, just local
neighborhood.
• Local names for neighbors.
– No particular order for neighbors, in general.
– But
B t (technicality)
(t h i lit ) if incoming
i i andd outgoing
t i edgesd connectt to
t same
neighbor, the names are the same (so the node “knows”this). 2
Leader election in general
• Assume:
synchronous networks
• Use UIDs with comparisons only
only.
• No constraints on which UIDs appear, or where they appear in the
g p
graph.
• Processes know (upper bound on) graph diameter.
• Required: Everyone should eventually set status ∈{leader,
{leader, non
non-
leader}, exactly one leader.
• Show basic floodingg algorithm,
g sketch pproof usingg invariants, show
optimized version, sketch proof by relating it to the basic algorithm.

• Basic flooding algorithm:


• Every round: Send max UID seen to all neighbors.
• Stop after diam rounds.
3
• Elect self iff own UID is max seen.
Leader election in general
• States
synchronous networks
– uu,initially
initially UID
– max-uid,initially UID
– status∈{unknown, leader, not-leader}, initially unknown
– rounds, initially 0
• Msgs
– if rounds < diam send max-uid to all out-nbrs
• Trans
– increment round
– max-uid:= max (max-uid, UIDs received)
– if round=
d diam
di then
h
• status:= leader if max-uid= u, not-leader otherwise 4
Leader election in general
synchronous networks
2
2
1 1
5
5
4
3 4

3
Start Configuration
6
6
5
Leader election in general
synchronous networks
2
2 2
1 2
1
1 2 5
3
5
1 5
4 4
3 4
5
3 6
6 Round 1 (msgs)
6
6
6
Leader election in general
synchronous networks
5
2 2
3 2
1
1 2 5
3
5
1 5
6 4
3 4
5
6 6
6 Round 1 (trans)
6
6
7
Leader election in general
synchronous networks
5
2
3 1
5
5
6
3 4

6
Round 2 (start)
6
6
8
Leader election in general
synchronous networks
5
5 2
3 5
1
3 5 5
6
5
3 5
6 6
3 4
5
6 6
6 Round 2 (msgs)
6
6
9
Leader election in general
synchronous networks
5
5 2
6 5
1
3 5 5
6
6
3 5
6 6
3 4
5
6 6
6 Round 2 (trans)
6
6
10
Leader election in general
synchronous networks
5
2
6 1
6
5
6
3 4

6
Round 3 (start)
6
6
11
Leader election in general
synchronous networks
5
5 2
6 5
1
6 5 6
6
6
6 5
6 6
3 4
6
6 6
6 Round 3 (msgs)
6
6
12
Leader election in general
synchronous networks
6
5 2
6 5
1
6 5 6
6
6
6 5
6 6
3 4
6
6 6
6 Round 3 (trans)
6
6
13
Leader election in general
synchronous networks
6
2
6 1
6
5
6
3 4

6
Round 4 (start)
6
6
14
Leader election in general
synchronous networks
6
6 2
6 6
1
6 6 6
6
6
6 5
6 6
3 4
6
6 6
6 Round 4 (msgs)
6
6
15
Leader election in general
synchronous networks
6
2
6 1
6
5
6
3 4

6
Round 4 (trans)
6
6
16
Leader election in general
networks
• Basic flooding algorithm (summary):
– Assume diameter is known (diam).
– Every round: Send max UID seen to all neighbors.
– Stop after diam rounds.
– Elect self iff own UID is max seen.
• Complexity:
– Time complexity
p y (rounds):
( ) diam
– Message complexity: diam|E|
• Correctness proof?

17
Key
y Invariant
• Invariant:After round r, if distance(i,j) ≤ r then
max uidj ≥ UIDi.
max-uid
• Proof:
• Induction on r.
– Base: r = 0
• distance(i,j) = 0 implies i = j, and max-uidi= UIDi.
– Inductive
I d ti step:
t Assume
A for
f r-1,
1 prove ffor r.
• If distance(i,j) ≤r then there is a node k in in-nbrsj such that
di t
distance(i,k)
(i k) ≤r
≤ -1.
1
• By inductive hypotheses, after round r-1, max-uidk≥UIDi.
• Since
Si k sends
d its
it max_uid id to
t j att roundd r, max-uid
idj≥UIDi after
ft
round r. 18
Reducing the message
complexity
• Slightly optimized algorithm:
– Don't send same UID twice.
– New state var: new-info: Boolean, initially true
– Send max
max-uid
uid only if new
new-info=
info true
– new-info:= true iff max UID received > max-uid

19
Leader election in general
synchronous networks
2
2
1 1
5
5
4
3 4

3
Start Configuration
6
6
20
Leader election in general
synchronous networks
2
2 2
1 2
1
1 2 5
3
5
1 5
4 4
3 4
5
3 6
6 Round 1 (msgs)
6
6
21
Leader election in general
synchronous networks
5
2 2
3 2
1
1 2 5
3
5
1 5
6 4
3 4
5
6 6
6 Round 1 (trans)
6
6
22
Leader election in general
synchronous networks
5
2
3 1
5
5
6
3 4

6
Round 2 (start)
6
6
23
Leader election in general
synchronous networks
5
5 2
3 5
1
3 5
6
5
3 5
6 6
3 4

6
Round 2 (msgs)
6
6
24
Leader election in general
synchronous networks
5
5 2
6 5
1
3 5
6
6
3 5
6 6
3 4

6
Round 2 (trans)
6
6
25
Leader election in general
synchronous networks
5
2
6 1
6
5
6
3 4

6
Round 3 (start)
6
6
26
Leader election in general
synchronous networks
5
2
6 1
6 6 6
6 5
6
3 4
6
6
Round 3 (msgs)
6
6
27
Leader election in general
synchronous networks
6
2
6 1
6 6 6
6 5
6
3 4
6
6
Round 3 (trans)
6
6
28
Leader election in general
synchronous networks
6
2
6 1
6
5
6
3 4

6
Round 4 (start)
6
6
29
Leader election in general
synchronous networks
6
6 2
6 1 6
6
6
5
6
3 4

6
Round 4 (msgs)
6
6
30
Leader election in general
synchronous networks
6
2
6 1
6
5
6
3 4

6
Round 4 (trans)
6
6
31
Leader election in general
synchronous networks
• Slightly optimized algorithm (summary):
– Don't send same UID twice
– New state variable:
i bl new-info:
i f Boolean,
l initially
i i i ll true
– Send max-uid just when new-info= true
– new-info:= true iff max UID received > max-uid
– Can improve communication cost drastically,
drastically though
not the worst-case bound, diam|E|.
• Correctness proof?
– As before, or:
– Can
C use another
th important
i t t prooff method
th d for
f distributed
di t ib t d
algorithms: simulation relations. 32
Simulation Relation
• Relates new algorithm formally to an original one that has
already been proved correct.
• Correctness then carries over to new algorithm.
algorithm
• Often used to show correctness of optimized algorithms.
• Can repeat in several stages, adding more optimizations.
• “Run the two algorithms side by side.”
• Define simulation relation between states of the two
algorithms:
– Satisfied by start states.
– Preserved
P d bby every ttransition.
iti
– Outputs should be the same in related states. 33
Simulation Relation for the
optimized algorithm
• Key invariant of the optimized algorithm:
– If i ∈in-nbrsj and max-uidi > max-uidj then new-infoi=
true.
– That is,
is if i has better information than j has,
has then i is
planning to send it to j on the next round.
– Prove by induction
induction.
• Simulation relation: All state variables of the basic
algorithm (all but new-info) have the same values in
both algorithms.
g
34
Simulation Relation for the
optimized algorithm
• Start condition: By definition.
• Preserved by every transition:
– Key property: max-uids are always the same in the two
algorithms.
algorithms
– Consider i ∈in-nbrsj.
– If new-infoi= true before the step, then the two
algorithms behave the same with respect to ( i, j).
– Otherwise, only the basic algorithm sends a message.
However,, byy the invariant,, max-uidi ≤ max-uidj before the
step, and the message has no effect.
35
Why all these proofs?

• Distributed algorithms can be quite


complicated, subtle.

• Easy to make mistakes.

• So careful reasoning about algorithm steps is


generally more important than for sequential
algorithms.
l ith
36
Breadth-first Search
• Assume:
– Strongly connected digraph,
digraph UIDs
UIDs.
– No knowledge of size, diameter of network.
– Distinguished source node i0.
• Required:
q Breadth-first spanning
p g tree,, rooted at
source node i0.
– Branches are directed paths in the given digraph.
digraph
– Spanning: Includes every node.
Breadth-first: Node at distance d from i0 appears at depth d
in tree.
– Output: Each node (except i0) sets a parent variable to
37
indicate its parent in the tree.
Breadth first Search
Breadth-first

2
1

3 4

38
Breadth first Search
Breadth-first

2
1

3 4

39
Breadth-first Search Algorithm
g
• Mark nodes as they get incorporated into the tree.
• I iti ll only
Initially, l i0 is
i marked.
k d
• Round 1:i0 sends search message
g to out-nbrs.
• At every round: An unmarked node that receives a
search message:
– Marks itself.
– Designates one process from which it received search as
its parent.
– Sends search to out-nbrs at the next round.
• Q:What state variables do we need?
• Q:Why does this yield a BFS tree? 40
Breadth first Search
Breadth-first

2
1

3 4

R
Round
d 1 ((start)
t t)
6

41
Breadth first Search
Breadth-first

2
1

5
S
3 4

R
Round
d 1 ((msgs))
6

42
Breadth first Search
Breadth-first

2
1

5
S
3 4

R
Round
d 1 (t
(trans))
6

43
Breadth first Search
Breadth-first

2
1

3 4

R
Round
d 2 ((start)
t t)
6

44
Breadth first Search
Breadth-first

2
1
S
5

3 4

S
R
Round
d 2 ((msgs))
6

45
Breadth first Search
Breadth-first

2
1
S
5

3 4

S
R
Round
d 2 (t
(trans))
6

46
Breadth first Search
Breadth-first

2
1

3 4

R
Round
d 3 ((start)
t t)
6

47
Breadth first Search
Breadth-first

S 2
1 S

S
5

3 4

S S
R
Round
d 3 ((msgs))
6

48
Breadth first Search
Breadth-first

S 2
1 S

S
5

3 4

S S
R
Round
d 3 (t
(trans))
6

49
Breadth first Search
Breadth-first

2
1

3 4

R
Round
d 4 ((start)
t t)
6

50
Breadth first Search
Breadth-first

2
1
S
S
S 5

3 4

R
Round
d 4 ((msgs))
6

51
Breadth first Search
Breadth-first

2
1
S
S
S 5

3 4

R
Round
d 4 (t
(trans))
6

52
Breadth first Search
Breadth-first

2
1

3 4

R
Round
d 5 ((start)
t t)
6

53
Breadth first Search
Breadth-first

2
1

3 4

R
Round
d 5 ((msgs))
6

54
Breadth first Search
Breadth-first

2
1

3 4

R
Round
d 5 (t
(trans))
6

55
Breadth-first Search Algorithm
g
• Mark nodes as they get incorporated into the tree.
• I iti ll only
Initially, l i0 is
i marked.
k d
• Round 1:i0 sends search message
g to out-nbrs.
• At every round: An unmarked node that receives a
search message:
– Marks itself; Designates one process from which it
received search as its parent; Sends search to out-nbrs at
the next round.
• Yields a BFS tree because all the branches are
created synchronously.
• Complexity:Time = diam+ 1; Messages = |E| 56
• Child pointers?
– Easyy with bidirectional communication.
– What if not?
• Could use BFS to search for parents.
parents
• High message bit complexity.
• Termination?
T i ti ?
– With bidirectional communication?
• “Convergecast”
–W
With
t unidirectional
u d ect o a cocommunication?
u cat o ?
57
Applications of BFS
• Global
Gl b l computation:
i
– Sum, max, or anyy kind of data aggregation:
gg g
Convergecast on BFS tree.
– Complexity: Time O(diameter); Messages O(n)
• Leader election (without knowing diameter):
– Everyone starts BFS, determines max UID.
– Complexity: Time O(diam); Messages O(n|E|)
(actually, O( diam|E|)).
• Compute diameter:
– All do BFS.
– Convergecast
C to fi
findd height
h i h off eachh BFS
S tree.
– Convergecast again to find max of all heights. 58
Shortest Paths
• Motivation: Establish structure for efficient
communication.
i i
– Generalization of Breadth-First Search.
– Now edges have associated costs (weights).
• Assume:
– Strongly connected digraph, root i0.
– Weights (nonnegative reals) on edges.
– Weights
g represent
p some communication cost,, e.g.
g latency.
y
• UIDs.
– Nodes know weights of incident edges.
edges
– Nodes know n (need for termination). 59
Shortest Paths
• Motivation: Establish structure for efficient
communication.
i i
• Assume:
• Required:
– Shortest-paths
h h tree, giving
i i shortest
h paths
h from
f i0 to
every other node.
– Shortest path = path with minimum total weight.
– Each node should output
p parent,
p , “distance” from root
(by weight).

60
Shortest Paths

7 2 0
10
1
5 1
6 8 11
5
2
3 4
4
9
3

61
Shortest Paths
10 3
7 2 0
10
1
5 1
6 8 11 2
5
2
4
3 0
4
9 3
9

6
6
62
Shortest path algorithm
• Bellman-Ford
Bellman Ford (adapted from sequential algorithm)
• “Relaxation algorithm”

• Each node maintains:


– dist, shortest distance it knows about so far, from i0
– parent, its parent in some path with total weight = dist
– round number
• Initially i0 has dist 0, all others ∞; parents all null

63
Shortest path algorithm
• At each round, each node:
– Send dist to all out-nbrs
– Relaxation step:
• Compute new dist = min(dist,
min(dist minj(dj + wji)).
))
• Update parent if dist changes.
• Stop after n-1 rounds
• Then (claim) dist contains shortest distance,
distance
parent contains parent in a shortest-paths tree.

64
Shortest Paths

∞ 7 2 0
10
1
5 1
6 8 11
5 ∞
2
4
3 0
∞ 9
4
3
Round 1 (start)
6

65
Shortest Paths

∞ 7 2 0
10
1 ∞ ∞
5 1
6

8 11 ∞ ∞ ∞
0 5
∞ 2
4 0
3 0

∞ 9
4
3
∞ ∞ Round 1 (msgs)
6

66
Shortest Paths

11 7 2 0
10
1 ∞ ∞
5 1
6

8 11 ∞ ∞ 2
0 5
∞ 2
4 0
3 0

∞ 9
4
3
∞ ∞ Round 1 (trans)
6

67
Shortest Paths

11 7 2 0
10
1
5 1
6 8 11
5 2
2
4
3 0
∞ 9
4
3
Round 2 (start)
6

68
Shortest Paths

11 7 ∞ 2 0
10
1 ∞
5 1
11 ∞ 2
6 8 0
11
5 2
∞ 2
4 0
3 0 2
∞ 4
3
9 ∞
∞ Round 2 (msgs)
6

69
Shortest Paths
3
11 7 ∞ 2 0
10
1 ∞
5 1
11 ∞ 2
6 8 0
11
5 2
∞ 2
4 0
3 0 2
19 4
3
9 ∞
∞ Round 2 (trans)
6
6
70
Shortest Paths
3
11 7 2 0
10
1
5 1
6 8 0
11
5 2
2
4
3 0
19 9
4
3
Round 3 (start)
6
6
71
Shortest Paths
3
11 7
3
2 0
10
1 3
5 3 1
11 2
6
19 8 0
11
5 2
2
4 0
3 0 2
19 96
4
3
6 Round 3 (msgs)
6
6
72
Shortest Paths
3
10 7
3
2 0
10
1 3
5 3 1
11 2
6
19 8 0
11
5 2
2
4 0
3 0 2
9 96
4
3
6 Round 3 (trans)
6
6
73
Shortest Paths
3
10 7 2 0
10
1
5 1
6 8 11
5 2
2
4
3 0
9 9
4
3
Round 4 (start)
6
6
74
Shortest Paths
3
10 7
3
2 0
10
1 3
5 3 1
10 2
6
9 8 0
11
5 2
2
4 0
3 0 2
9 96
4
3
6 Round 4 (msgs)
6
6
75
Shortest Paths
3
10 7
3
2 0
10
1 3
5 3 1
10 2
6
9 8 0
11
5 2
2
4 0
3 0 2
9 96
4
3
6 Round 4 (trans)
6
6
76
Shortest Paths
3
10 7 2 0
10
1
5 1
6 8 11
5 2
2
4
3 0
9 9
4
3
Round 5 (start)
6
6
77
Shortest Paths
3
10 7
3
2 0
10
1 3
5 3 1
10 2
6
9 8 0
11
5 2
2
4 0
3 0 2
9 96
4
3
6 Round 5 (msgs)
6
6
78
Shortest Paths
3
10 7
3
2 0
10
1 3
5 3 1
10 2
6
9 8 0
11
5 2
2
4 0
3 0 2
9 96
4
3
6 Round 5 (trans)
6
6
79
Shortest Paths
3
10 7 2 0
10
1
5 1
6 8 11
5 2
2
4
3 0
9 9
4
3
End Configuration
6
6
80
Correctness
• Need to show that, after round n-1, for each
process i:
p
– disti = shortest distance from i0
– parenti = predecessor on shortest path from i0

• Proof:
– Induction on the number r of rounds.
rounds
– But, what statement should we prove about the
situation
it ti after
ft r rounds?
d?
81
Correctness
• Key invariant:
– After r rounds: Every process i has its dist and
parent corresponding
di to a shortest
h pathh from
f i0 to i
among those paths that consist of at most r
h ( d )
hops(edges).
– If there is no such path, then dist = ∞ and parent =
null.

82
Correctness
• Proof (sketch):
– By induction on the number r of rounds.
– Base: r = 0: Immediate from initializations.
– Inductive step:
p Assume for r-1,, show for r.
• Fix i; must show that, after round r, disti and parenti correspond
to a shortest at-most-r-hop path.
• First, show that, if disti is finite, then it really is the distance on
some at-most-r-hop path to i, and parent is its parent on such a
path.
• easy use of inductive hypothesis.
• But we must still argue that disti and parenti correspond to a
shortest at-most-r-hop path. 83
Complexity
p y
• Complexity:
– Time: n-1 rounds
– Messages: (n-1) |E|
• Worse than BFS, which has:
– Time: diam rounds
– Messages: |E|
• Q
Q: D
Does ththe ti
time bound
b d really
ll depend
d d on n, or is
i it
O(diam)?
• A: It’s really n, since “shortest path” can be over a
path with more links.
links
84
Minimum Spanning Tree
• Construct a spanning tree, minimizing the total
weight of all edges in the tree.
tree
• Assume:
– Weighted undirected graph (bidirectional
communication).
• Weights are nonnegative reals.
• Each node knows weights of incident edges.
– Processes have UIDs.
– Nodes know (a good upper bound on) n.
n
• Required:
– Each process should decide which of its incident edges
are in MST and which are not. 85
Minimum spanning tree theory
• Graph theory definitions (for undirected
g p )
graphs)
– Tree: Connected acyclic graph
– Forest: An acyclic graph (not necessarily
connected)
– Spanning
S i subgraph
b h off a graphh G:
G Subgraph
S b h that
h
includes all nodes of G.
• Spanning tree, spanning forest.
– Component of a graph: A maximal connected
subgraph.
86
Minimum spanning tree theory
• Common strategy for computing MST:
– Start with trivial spanning
p g forest,, n isolated nodes.
– Repeat (n-1 times):
• Merge two components along an edge that connects
them.
• Specifically,
Specifically add the minimum
minimum-weight
weight outgoing edge
(MWOE) of some component to the edge set of the
current forest.

87
Why this works
• Similar argument to sequential case.
• Lemma 1: Let { Ti: 1 ≤ i ≤ k } be a spanning
forest of G. Fix any j, 1 ≤ j ≤ k . Let e be a
minimum weight outgoing edge of Tj. Then
there is a spanning tree for G that includes all
the Tis and e, and has minimum weight among
p
all spanningg trees for G that include all the Tis.

88
MST algorithms
• General
G l strategy:
t t
– Start with n isolated nodes.
– Repeat (n-1 times):
• Choose some component
p i.
• Add the MWOE of component i.
• Sequential MST algorithms follow this strategy:
– Dijkstra/Prim: Grows one big component by adding one
more node
d att eachh step.
t
– Kruskal: Always add min weight edge globally.
• Distributed?
– All components can choose simultaneously
simultaneously.
– But there is a problem… 89
Minimum spanning tree
• Avoid this problem by assuming that all weights
are distinct.
di ti t
• Not a serious restriction---could break ties with
UIDs.
• Lemma 2: If all weights are distinct,
distinct then the
MST is unique.
• Proof: Another cycle argument.

90
Minimum spanning tree
• Justifies the following concurrent strategy:
– At each stage, suppose (inductively) that the current
forest contains only edges from the unique MST.
– Now several components choose MWOEs concurrently
concurrently.
– Each of these edges is in the unique MST, by Lemma 1.
– So OK to add them all (no cycles, since all are in the
same MST).
• GHS (Gallager, Humblet, Spira) algorithm
– Very influential (Dijkstra prize).
prize)
– Designed for asynchronous setting, but simplified here.
– We will
ill revisit
i i it
i in
i asynchronous
h networks.
k
91
GHS distributed MST algorithm
g
• Proceeds in phases (levels), each with O(n) rounds.
– Lengthh off phases
h is
i fixed,
fi d andd known
k to everyone.
– This is all that n is used for.
– We’ll remove use of n for asynchronous algorithm.

• For each k ≥ 0, level k components form a spanning


f
forest that
h isi a subgraph
b h off the
h unique
i MST.
MST

92
GHS distributed MST algorithm
g
• Each component is a tree rooted at a leader node.
– Component
C identified
id ifi d byb UID off leader.
l d
– Nodes in the component know which incident edges are
in the tree.
• Each level k component has at least 2k nodes.
• Every level k+1 component is constructed from two
or more level
l l k components.
• Level 0 components:
p Single
g nodes.
• Level k → level k+1:

93
Level k → level k+1
• Each level-k component leader finds MWOE
p
of its component:
– Broadcasts search (via tree edges).
– Each process finds the MWOE among its own
incident edges.
•S
Sends
d ttestt messages along
l non-tree
t edges,
d asking
ki if
node at the other end is in the same component
(compare component ids).
– Convergecast the min back to the leader (via tree
edges).
edges)
– Leader determines MWOE. 94
Level k → level k+1 (cont’d)
(cont d)
• Combine level-k components using MWOEs,
( ) components:
to obtain level(k+1) p
– Wait long enough for all components to find
MWOEs.
MWOEs
– Leader of each level k component tells endpoint
nodes of its MWOE to add the edge for level k+1.
k+1
– Each new component has ≥ 2k+1 nodes, as claimed.

95
Level k → level k+1 (cont’d)
• Each
h level-k
l l k component leader
l d finds
fi d MWOE
O off its
i
component.
• Combine level-k components using MWOEs, to
obtain level-(k+1)components.
level (k+1)components
• Choose new leaders:
– For each new, level k+1 component, there is a unique
edge
g e that is the MWOE of two level k sub-components
p
– Choose new leader to be the endpoint of e with the larger
UID.
– Broadcast leader UID to new (merged) component.
• GHS terminates
i when
h there
h are no more outgoing
i
edges. 96
Note on Synchronization
• This simplified version of GHS is designed to
p
work with component levels synchronized.
y
• Difficulties can arise when they get out of
synch.
synch
• In particular, test messages are supposed to
compare leader UIDs to determine whether
endpoints are in the same component.
• Requires that the node being queried has up-
t d t UID iinformation.
to-date f ti
97
Minimum spanning tree
4 g
a d k
10
2
12 5 i
9
c 1 f 7
13

0 8
3

b e j
6 h 11

98
Minimum spanning tree
4 g
a d k
10
2
12 5 i
9
c 1 f 7
13

0 8
3

b e j
6 h 11

99
Minimum spanning tree
4 g
a d k
10
2
12 5 i
9
c 1 f 7
13

0 8
3

b e j
6 h 11

100
Minimum spanning tree
4 g
a d k
10
2
12 5 i
9
c 1 f 7
13

0 8
3

b e j
6 h 11

101
Minimum spanning tree
4 g
a d k
10
2
12 5 i
9
c 1 f 7
13

0 8
3

b e j
6 h 11

102
Minimum spanning tree
4 g
a d k
10
2
12 5 i
9
c 1 f 7
13

0 8
3

b e j
6 h 11

103
Minimum spanning tree
4 g
a d k
10
2
12 5 9 i
9
c 1 f 7
13

0 8
3

b e 11 j
6 h 11

104
Minimum spanning tree
4 g
a d k
10
2
12 5 i
9
c 1 f 7
13

0 8
3

b e j
6 h 11

105
Minimum spanning tree
4 g
a d k
10
2
12 5 i
9
c 1 f 7
13

0 8
3

b e j
6 h 11

106
Minimum spanning tree
4 g
a d k
10
2
12 5 i
9
c 1 f 7
13

0 8
3

b e j
6 h 11

107
Minimum spanning tree
4 g
a d k
10
2
12 5 i
9
c 1 f 7
13

0 8
3

b e j
6 h 11

108
Simplified GHS MST Algorithm
• Complexity:
p y
– Time: O(n log n)
• n rounds for each level log n levels,
levels because there are ≥ 2k
nodes in each level k component.
– Messages: O( (n + |E|) log n)
• Naïve analysis.
• At each level
level, O(n) messages sent on tree edges
edges, O(|E|)
messages overall for all the test messages and their responses.
– Messages: O(n log n + |E|)
• A surprising, significant reduction.
• Trick also works in asynchronous setting
setting.
• Has implications for other problems, such as leader election.
109
O(n log n + |E|) message
complexity
• Each process marks its incident edges as
j
rejected when they y are discovered to lead to
the same component; no need to retest them.
• At each level
level, tests candidate edges one a time
time,
in order of increasing weight, until the first one
is found that leads outside (or exhaust
candidates))
• Rejects all edges that are found to lead to same
component.
component
• At next level, resumes where it left off. 110
O(n log n + |E|) message
complexity
• O(n log n + |E|) bound:
– O(n)
( ) for messages
g on tree edges
g at each pphase,, O(n
( log
g n))
total.
– Test,
Test accept (different component)
component), reject (same
component):
• Amortized analysis.
analysis
• Test-reject: Each (directed) edge has at most one test-reject, for
O(|E|) total.
total
• Test-accept: Can accept the same directed edge several times;
p pper node pper level,, O(n
but at most one test-accept ( logg n)) total.
111
Spanning tree → leader
• Given any spanning tree of an undirected graph,
elect a leader:
– Convergecast from the leaves, until messages meet at a
node (which can become the leader) or cross on an edge
(chooseendpoint with the larger UID).
– Complexity: Time O(n); Messages O(n)
• Given any weighted connected undirected graph,
with known n, but no leader, elect a leader:
– First use GHS MST to get a spanning tree, then use the s
panning tree to elect a leader.
– Complexity: Time O(n log n); Messages O(n log n + |E|).
|E|)
– Example: In a ring, O(n log n) time and messages. 112

You might also like