GHS - MST Algorithm
GHS - MST Algorithm
Pallab Dasgupta
Professor,
Dept. of Computer Sc. & Engg.,
Indian Institute of Technology Kharagpur
1
Minimal Spanning Tree
Let G = (V, E) be a weighted graph, where (e) denotes the weight of edge e.
– The weight of a spanning tree T of G equals the sum of the weights of the N – 1 edges
contained in T
– T is called a minimal spanning tree if no spanning tree has a smaller weight than T.
2
Two Properties of MST’s
Cycle Property: For any cycle C in a graph, the heaviest edge in C does not appear in the minimum spanning tree
• Used to rule edges out
Cut Property: For any proper non-empty subset X of the vertices, the lightest edge with exactly one endpoint in X
belongs to the minimum spanning forest
• Used to rule edges in
Simplifying assumption : All edge costs are distinct.
Let S be any subset of vertices, and let e be the min cost edge with exactly one endpoint in S.
Then the MST T* contains e.
Pf. [by contradiction]!
Suppose e does not belong to T*.
Let's see what happens.
Adding e to T* creates a (unique) cycle C in T* since
Some other edge in T*, say f, has exactly one end point in S.
T = T* + {e} - {f} is also a spanning tree.
Since c(e)<c(f), cost(T) < cost(T*).
This is a contradiction.
The notion of a fragment
A fragment is a subtree of a MST
If F is a fragment and e is the least-weight outgoing edge of F, then F U {e} is a fragment
Prim’s Algorithm:
– Start with a single fragment and enlarges it in each step with the lowest-weight
outgoing edge of the current fragment
Kruskal’s Algorithm:
– Starts with a collection of single-node fragments and merges fragments by adding the
lowest-weight outgoing edge of some fragment
5
Gallager-Humblet-Spira Algorithm
6
Gallager-Humblet-Spira Algorithm
Algorithm Outline:
1) Start with each node as a one-node fragment
2) The nodes in a fragment cooperate to find the lowest-weight outgoing edge of the
fragment
3) When the lowest-weight outgoing edge of a fragment is known, the fragment will be
combined with another fragment by adding the outgoing edge, in cooperation with the
other fragment
4) The algorithm terminates when only one fragment remains
7
Gallager-Humblet-Spira Algorithm
Notations and Definitions:
1) Fragment name. To determine whether an edge is an outgoing edge, we need to give
each fragment a name. // similar to having the same root node in union find for all nodes
in the same fragment
2) Fragment levels. Each fragment is assigned a level, which is initially 0 for an initial one-
node fragment.
3) Combining large and small level fragments. The smaller level fragment combines into the
larger level fragment by adopting the fragment name and level of the larger level
fragment. Fragments of the same level combine to form a fragment of a level which is one
higher than the two fragments. The new name is the weight of the combining edge, which
is called the core edge of the new fragment.
8
Gallager-Humblet-Spira Algorithm
Summary of combining strategy: A fragment F with name FN and level L is denoted as F
= (FN, L); let eF denote the lowest-weight outgoing edge of F.
– Rule A. If eF leads to a fragment F = (FN, L) with L < L, F combined into F, after
which the new fragment has name FN and level L. These new values are sent to all
processes in F
– Rule B. If eF leads to a fragment F = (FN, L) with L = L and eF = eF, the two
fragments combine into a new fragment with level L+1 and name (eF). These new
values are sent to all processes in F and F.
– Rule C. In all other cases fragment F must wait until rule A or B applies.
So if joining with a lower fragment then the larger fragment will wait.
9
Gallager-Humblet-Spira Algorithm
Node and link status:
10
var statep : (sleep, find, found) ;
11
end
GHS Algorithm: Part-1
(2) Upon receipt of connect, L from q:
begin if L < levelp then (* Combine with rule A *)
end
else //L=levelp as connect not called on L>levelp due to test code
if statusp[q] = basic //other side did not find the same min outgoing edge
12
Question ---
else //L>=levelp
if statusp[q] = basic
then (* Rule C *) process the message later
else (* Rule B *) send initiate, levelp + 1, (pq), find to q
end
Assume for now that the future code ensures that statusp[q]=basic only if p’s level is smaller (this is
taken care of by test function). Hence you can assume now Rule B applies in the else part.
How does the code make sure that the two fragments of equal size are connected only if both sides have
identified the same min outgoing edge?
13
GHS Algorithm: Part-1
(3) Upon receipt of initiate, L, F, S from q:
begin levelp := L ; namep := F ; statep := S ; fatherp := q ;
send initiate, L, F, S to r ;
if statep = find then begin recp := 0; test end
end
//Procedure test is called on a node asking it to check for its min outgoing edge followed by
reporting to its parent the min outgoing edge among those reported by its subtree compared
to its own.
14
Testing the edges - To find its lowest-weight outgoing edge
To find its lowest-weight outgoing edge, node p inspects its outgoing edges in increasing
order of weight.
To inspect edge pq, p sends a test, levelp, namep message to q and waits for an answer
– A reject message is sent by process q if q finds that p’s fragment name is the same as
q’s fragment name. On receiving the reject message, p continues its local search.
– If the fragment name differs q sends an accept message provided the level is smaller
(read below)
– The processing of a test, L, F message is deferred by q if L > levelq because p and q
may actually belong to the same fragment, but the initiate, L, F, S message has not
yet reached q
15
A simple optimization
To inspect edge pq, p sends a test, levelp, namep message to q and waits for an answer
16
Test node – check who is your min outgoing edge
(4) procedure test
Basic edge can be to own fragment
begin if q Neighp : statchp[q] = basic then Or to other fragment. If already branch or
reject then we cant consider it for the min
outgoing edge
begin let testchp := q when
end
else begin testchp := udef ; report
Testend
procedure is when a node is asked to
check its incident basic edges in increasing order of
end weight to find an edge going out to another fragment.
17
in which case it sends the min wt edge to its parent.
GHS Algorithm: Part-2
(5) Upon receipt of test, L, F from q:
begin if L > levelp then (* Answer must wait *)
end
else send accept to q
18
end
Inconsistent test queries - question
Suppose we have two equal sized fragments F1 and F2 which have sent each other the initiate
msg with status find. The initiate msg as we know sends initiate and test msgs
down the tree to further children. Meanwhile, suppose that an initialised node of one fragment F1
sends a test to an uninitialised node of F2. F2 will find its fragment name to
be different from the requested node and will accept. Issue?
Similar case : Suppose we have two unequal sized fragments F1 (larger) and F2 where F1 has
sent F2 an initiate msg with status find. The initiate msg as we know sends initiate and test msgs
down the tree to further children. Meanwhile, suppose a node of F1 sends a test to an uninitialised
node of F2. F2 will find its fragment name to be different from the requested node and will accept.
Issue?
19
GHS Algorithm: Part-2
(6) Upon receipt of accept from q://local search of outgoing edge is done.
begin testchp := udef ; //indicate that local search is over
if (pq) < bestwtp//bestp is the best wt p has seen among its own and its subtree
then begin bestwtp := (pq) ; Each time a <report,w> msg reaches,
the value of bestwtp is updated.
bestchp := q The current bestwtp is the best among
what it has received so far. Each
end ; ‘report’ checks if all msgs <report,w>
msgs have reached and local computation
report is complete in order to send result to parent.
end
(7) Upon receipt of reject from q:
begin if statchp[q] = basic then statchp[q] := reject ;
test
end
20
Reporting the lowest-weight outgoing edge
The lowest-weight outgoing edge is reported for each sub tree using report, messages
– Node p counts the number of report, messages it receives, using the variable
recp.
The report, messages are sent in the direction of the core edge by each process.
– The messages of the two core nodes cross on the edge; both receive the message
from their father
– When this happens, the algorithm terminates if no outgoing edge was reported.
Otherwise a connect, L message must be sent through this edge.
21
Sending the connect
If an outgoing edge was reported, the lowest-weight outgoing edge is found by
following the bestch pointer in each node, starting from the core node on whose
side the best edge was reported
This is done by sending a changeroot message.
When the changeroot message arrives at the node incident to
the lowest-weight outgoing edge, this node sends a connect, L
message via the lowest-weight outgoing edge.
22
GHS Algorithm: Part-3
procedure report://if the number of msgs received is equal to its children and its own
search has concluded(testchp-udef) then put state as found and send report to
father. A report call is a check to see if all <report,w> msgs have reached.
begin if recp = #{ q : statchp[q] = branch q fatherp }
end
end
23
24
GHS Algorithm: Part-3
(9) Upon receipt of report, from q:
begin if q fatherp // at the core edge p and q are fathe of eachother. Could have put condn as if pq not core edge
then (* reply for initiate message *)
begin if < bestwtp then
begin bestwtp := ; bestchp := q end ;
recp := recp + 1 ; report // report called again to chk if it has got all msgs to send to parent
end
else (* pq is the core edge *)
if statep = find// p is still looking for min outgoing while q’s result arrives so make q wait
then process this message later
else //state is found
if > bestwtp //if w<bestwtp then q will do changeroot when it gets <report,w>. Wt w!=bestwtp as unique edge
weights
then changeroot
else if = bestwtp = then stop //when both don’t have anything to report then both
report infinity implying single fragment. Then stop
25
end
GHS Algorithm: Part-3
(10) procedure changeroot://if you are the node having the min edge then you send
connect. Else you send changeroot to your child trhough which you got the min edge
begin if statchp[bestchp] = branch
then send changeroot to bestchp
else begin
statchp[bestchp] := branch //this takes care of p and q connecting on the
same edge if both have same levels by rule2
send connect, levelp to bestchp ;
end
end
26
Complexity
The Gallager-Humblet-Spira algorithm computes the minimal spanning tree using at
most 5N logN + 2|E| messages
– Each edge is rejected at most once and this requires two messages
(test and reject). This accounts for at most 2|E| messages.
– At any level, a node receives at most one initiate and one accept
message, and sends at most one report, one changeroot or connect
message, and one test message not leading to a rejection. For logN
levels, this accounts for a total of 5N logN messages.
27