Ugg join all caves with least walking — and no chief to help
Ugg have caves. Trails join them, some short, some long. Ugg want pick trails so ALL caves joined with least total walking, no wasted loop. That the minimum spanning tree (MST).
A spanning tree touch all caves with exactly trails and no loops. The MST the one with smallest total trail-length — and if every trail have a different length, the MST is ONE answer, no tie.
Easy when a big chief stand on a hill and see ALL the land (chief-magic Prim, chief-magic Kruskal). But Ugg have NO chief — each cave know only its own trails and their length. This the hard distributed hunt: no god-eye, talk only by runner-message. The clever plan is GHS (Gallager, Humblet, Spira).
Two rock-laws that make MST easy
Cut property — draw a line, split caves into two piles. The SHORTEST trail crossing the line MUST be in the MST. This puts trails IN. In stone-marks: — for any cave-pile , its lightest leaving-trail belong to the answer.
Cycle property — in any circle-loop of trails, the LONGEST trail is NEVER in the MST. This throws trails OUT.
GHS is built on the cut property. Why is it true? Pretend the shortest crossing trail is NOT in the tree. Add it — a loop appear holding another crossing trail with . Swap for : tree still whole but LIGHTER. So the old tree was not smallest — lie! So must be in the MST. Ugg happy.
Tribes and their leaving-trail
A fragment is a tribe — caves already joined by good trails (a piece of some MST). Start: every cave alone, its own tiny tribe. Each tribe carry a name and a level (rank); a baby tribe is level 0 with name = its cave-id.
The MWOE (minimum-weight outgoing edge) is the tribe's shortest leaving-trail — lightest trail with one end inside, one end outside. Big lemma: add the MWOE and the tribe is STILL good (still a piece of the MST). This the beating heart of GHS.
The core edge is the wedding-trail that last joined two tribes; its length become the tribe's new name.
GHS is Kruskal done distributed. Prim grow ONE tribe by its MWOE; Kruskal start all caves alone and merge tribes by MWOE. GHS do Kruskal with MANY hands — many tribes grow at once. Ugg warn: GHS is NOT Prim!
Three joining-rules — learn these by the fire
Tribe (level ) wants join tribe (level ) across 's leaving-trail :
- Rule A (Absorption): . Small tribe rush into big one; new tribe keep 's name and level.
- Rule B (Merger): AND both tribes pick the SAME trail (point at each other). Merge into a fresh tribe, level , name — that trail is the new core edge.
- Rule C (Wait): any other case — WAIT.
Why wait? If Ugg tribe is big and the other is small and NOT pointing back, that small one is still growing — it will grow up and re-choose. Rush now make a bad marriage.
Test, Accept, Reject — how a cave find its leaving-trail
Cave look at its basic edges (trails not yet judged), shortest first, and send a test ⟨⟩ runner down each trail . Cave answer:
- reject if — same tribe, inside trail, throw out.
- accept if AND — different tribe, and big enough to be sure. Good candidate.
- defer (wait to answer) if — smaller; maybe is about to join 's tribe but the news not reach it yet. Answer later when the level catch up.
The defer case the tricky one — skip it and Ugg mark trails wrong, miss later marriages. Trick: if tested and tested , only ONE reject is needed. Ugg warn: accept do NOT mean "trail in MST" — only "eligible"; the true winner get picked later by report-gathering.
Report, changeroot, stop — and the five runners
Runner-calls in GHS: connect ⟨⟩ (ask to join), initiate (shout the new level/name into the tribe and start a new leaving-trail hunt), test, accept / reject, report ⟨⟩ (send the smallest leaving-trail up toward the core), and changeroot (travel from the core down to the cave on the winning trail, tell it to send connect).
Each cave report the smallest leaving-trail — its own and its children's — up toward the core edge. The core-side with the smaller number send changeroot to the cave on the true MWOE, which fire connect — waking Rule A or B next door.
Stop when both core-ends report (no leaving-trail anywhere). One tribe left — that tribe IS the MST.
How tall a tribe grow, and how many runners
Rank grow ONLY when two same-level tribes merge (Rule B). A level- tribe hold at least caves — two level- tribes stuck together, doubling each merge. So with caves: **max level **. Ugg warn: max level is NOT — it double, not count one-by-one!
Cost: runner-messages ( = number of trails), and time. The come from initiate-shouts at each of the rank-jumps. BEST any compare-based distributed MST hunt can do.
Fire-story: four caves
Trails A-B(1), B-C(2), C-D(3), A-D(5), A-C(4), B-D(6). Start: 4 tribes, all level 0. Leaving-trails: A→B(1), B→A(1), C→B(2), D→C(3).
A and B same level and both point at AB — Rule B: merge to {A,B}, level 1, name .
C's leaving-trail BC(2) points at {A,B} (now level 1). C is level — Rule A, rush in → {A,B,C} level 1. D the same way by CD(3) — Rule A → {A,B,C,D} level 1.
No trail leave — stop. MST = {AB, BC, CD}, total walking . With 4 caves the max level is .
Ugg remember
- Cut law rules trails IN, cycle law rules trails OUT. GHS lives on the cut law: the shortest leaving-trail (MWOE) is always in the MST.
- Three rules — A: small rush into big; B: equal level + mutual trail → merge to level+1; C: else WAIT. Rule B is the ONLY rule that raises the rank. Every question hide here.
- **Test answers — reject = same tribe; accept = different tribe + ; defer = different + .** Accept means "eligible", not "in MST".
- **Max level ** (doubling), NOT . Cost runners — best possible.
- GHS is distributed Kruskal, not Prim — many tribes grow together, joining by mutual leaving-trail.