46
Minimum Spanning Tree 吳吳吳 吳吳吳吳 吳吳吳吳 、、、 吳吳吳 吳吳吳吳 吳吳吳 、、

Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Embed Size (px)

Citation preview

Page 1: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Minimum Spanning Tree

吳光哲、江盈宏、陳彥宏、鍾至衡、張碧娟、余家興

Page 2: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Outline

• History of MST

• Background Knowledge: Soft Heap

• Algorithm at a Glance

• The MST algorithm

• Notations

• Detail description

• Correctness

Page 3: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

History of MST(1/2)

• 1926, Boruvka present the first model to solve MST.

• Textbook algorithms run in O(mlogn), Kruskal’s Greedy Algorithm, Prim’s Algorithm

• 1975, Yao, O(mloglogn)• 1984, Freeman and Tarjan, O(mβ(m,n))• 1987, Gabow, O(m logβ(m,n)), involved a new dat

a structure : Fibonacci Heap

Page 4: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

β(m,n)

β(m,n) is a very slowly growing function defined as follows:

β(m,n) = min { i : logi(n)<= m/n}

The worst case is O(m log*m) (m = O(n))

Page 5: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

History of MST(2/2)

• 1997, Bernard Chazelle, O(mα(m, n)log α(m, n))

Problem: Does there exists a linear deterministic algorithm which solves MST problem?

Hope : for a given weighted connected graph G with m edges the algorithm finds a MST of G in at most Km steps?

Page 6: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

α(m,n)

α(m,n) is the “inverse” of Ackermann's function (a very slowly growing function)

α(m,n) = { k>=1: A(k,m/n)>lgn}

Ackermann’s function is defined by

A(1,m) = 2m

A(n,1) = A(n-1,2)

A(n,m) = A(n-1,A(n,m-1))

Page 7: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

TODAY

• A Minimum Spanning Tree Algorithm with Inverse-Ackermann Type Complexity-- Bernard Chazelle -- Princeton University, and NEC Research Institute-- Journal of the ACM, November 2000-- involved a new data structure : Soft Heap-- Running time is O(mα(m,n))

• An Optimal Minimum Spanning Tree Algorithm-- Seth Pettie And Vijaya Ramachandran-- The University of Texas at Austin, Austin, Texas-- Journal of the ACM, January 2002-- involved a new data structure : Soft Heap-- Runs in time O(T*(m,n)), T*(m,n) is beteween (m) & O(mα(m,n))

Page 8: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Soft Heap

• A variant of a binomial heap-create(H): Create an empty soft heap-insert(H,x): Add new item x to H-meld(H,H’): Union in H and H’.-delete(H,x): Remove item x from H.-findmin(H): return the smallest key in H.

• The amortized complexity of each operation is constant, except for insert, which takes O(log 1/)

is the error rate in soft Heap.

Page 9: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Binomial Heap

In Worst-case• Make-Heap (1) Insert O(lgn)• Meld O(lgn) Delete (lgn)• Findmin (lgn)

Page 10: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Key Point

• The entropy of the data structure is reduced by Artificially raising the values of certain keys. (corrupted)

• Move items across the data structure not individually, but in groups.(car pooling)

is the error rate in soft Heap.

• Deletemin() -> sift()

Page 11: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Algorithm at a Glance (1/4)

Input: an undirected graph G.– Each edge e is assigned a cost c(e)– Edge costs are distinct– MST(G) is unique

– There are m edges– There are n vertices

Page 12: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Algorithm at a Glance (2/4)

Contractibility (for a subgraph C of G)– C is contractible if C ∩ MST(G) is connected.– Computing MST(C) is easier.– How can we discover C without computing MST(G)?

C is not contractible

1

2

34

5

C is contractible

C

C

Page 13: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Algorithm at a Glance (3/4)

Decompose Contract Glue

Step. 1 Step. 2

Step. 4Step. 3

Page 14: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Algorithm at a Glance (4/4)

Iterating this process forms a hierarchy tree

Each v of G is a leaf of

The hierarchy tree

Page 15: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Finally, the MST algorithm.

To computer MST of G, call msf(G, t) with

msf(G, t)

We will explain this later.

Page 16: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Any question?

We are going into the details now….

Page 17: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

And

Let’s welcome 光哲兄 ~

Page 18: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

• Computed in O(m+d3n)

• Balance between height and node:Ackermann’s function

Tree

zCz

height dznz

Page 19: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Ackermann’s function

• Choice nz as

Page 20: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

By induction on t, we haveExpansion of Cz=S(t,dz)3

Compute tree in bt(m+d3n)=O(m+d3n)d=(m/n)1/3

The choice of t and d implies that t=O(α(m,n))MST is O(mα(m,n))

Page 21: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Active path

z1

z2

z3

z4=zk

Page 22: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Border edges

• Exactly one vertex in

Cz1

Cz2

Cz3

Cu

z1

z2

z3

u

Page 23: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Corrupted edge

• Border edges are stored in soft heaps

• They may become corrupted due to soft heap operation.

• If it’s corrupted:

corrupted

CzCz

Cost++Soft heap

Page 24: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Bad edge

• It’s called bad if

corruptedbad

When Cz contracted into one vertex

Cz Cz

Once bad always bad

Page 25: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Working cost

Cz

corrupted

Cz

Cost++bad

Cz

Working cost=original cost Working cost=current cost

Page 26: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Stack view z1

z2

z3z4=zk

Page 27: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Detail description of each steps

• Totally 5 steps.

• Many details for Step [3].

• Detail but not too detail (hopefully).

Page 28: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Step[1, 2]

Case t=1 is special. Solve this in O(n2)– Because

What if G is not connected?– Apply msf to each connected component.

What if G is not simple?– Keep only the cheapest edge.

The aim of performing Boruvka is to reduce the number of edges (to n/2c).

Page 29: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Step[3]

Building the hierarchy– With t > 1 specified, target size nz is specified.

– We discuss for a general case that the active path is z1, z2, …zk

– Keep two invariants: INV1 and INV2 (explain later)

– Two possible actions: Retraction and Extension.

Page 30: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

INV1For all i<k

chain link e

for any two pair (j1, j2)<i

Page 31: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Step[3]: INV2

Each border edge (u, v) where u Czj are store

d into H(j) or H(i, j)– No edge appears in more than one heap– Membership in H(j) implies v is

incident to at least one edge insome H(i, j)

– Membership in H(i, j) implies

v is also incident to Czi but not

any Czl that (i<l<j) Czj

CziCzi-1

u

v

Page 32: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Step[3]: INV2

A practice

V

Z1

a

b

cd

e

fg

Z5

Z2

Z3

Z4

A possible assignment of edges to heaps:

a H(4,5),b H(4),

c H(2,4), d H(2),

e H(1,2), f H(1,2),

g H(0,1)

Page 33: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Step[3]: Retraction

If a last subgraph Czkhas attained its target size.

– Contract Czkinto Czk-1

(as well as its links)

– Czk-1 gains one vertex.

– Destroy H(k) and H(k-1, k)• Discard bad edges.• For each cluster, insert the

minimum edge implied by INV2.

– Meld H(i, k) into H(i, k-1) a cluster

Page 34: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Step[3]: Extension

Do findmin on all heaps and retrieve the border edge (u,v) with minimum cost.– (u,v) is the extension edge (chain-link also)

– v is the first vertex in Czk+1

– Older border edges incident to v are not border edges now. Delete them from heap, update min-links and insert new border edges.

Page 35: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Step[3]: Extension

If any min-link (a, b) is less than (u, v)– We have to do a fusion– Explain by the figure.

CZi CZk CZi

ab

v

u

a

Becomes

v

fusion into a

Page 36: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Step[3]: Conclusion

Keep doing Extension until target size is reached or no vertices is left.

Perform Retraction when target size is reached.

Maintain INV1 and INV2 at the same time.

Page 37: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Step[4]

Recursing in Subgraphs of  .– For every Cz, do msf(Cz -1, t-1)

– The edge cost are resetted to original value.– The main goal is to modify the target size.– For every fusion edge (a, b), this fusion does no

t occur anymore in Cz.

Page 38: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Step[5]

The final recursion– The candidate edge set becomes F∪B now.– Adding edges contracted in Step[2] produces

MST of G.

Page 39: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Correctness

Contractibility– Subgraph C of G is strong contractible if

each edge of π < min(e, f )– That’s why we do fusion.

Lemma 3.1: If an edge e is not bad and lies outside F, e lies outside of MST(G).

C

fe

π

Page 40: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

MST(G) and T

Cz

zCz

z: tree nodeCz: subgraph(vertex)

Page 41: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

a cluster

CzjCzi

Czi-1

u

v

Page 42: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

V

Z1

a

b

cd

e

fg

Z5

Z2

Z3

Z4

Page 43: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Page 44: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Page 45: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm

Page 46: Minimum Spanning Tree 吳光哲、江盈宏、陳彥宏、 鍾至衡、張碧娟、余家興. Outline History of MST Background Knowledge: Soft Heap Algorithm at a Glance The MST algorithm