minimum spanning trees

19
UNC Chapel Hill Lin/Foskey/Manocha Minimum Spanning Trees Problem: Connect a set of nodes by a network of minimal total length Some applications: Communication networks Circuit design Layout of highway systems Aquí radica la importancia del concepto

Upload: paul-mcintyre

Post on 03-Jan-2016

34 views

Category:

Documents


0 download

DESCRIPTION

Minimum Spanning Trees. Problem: Connect a set of nodes by a network of minimal total length Some applications: Communication networks Circuit design Layout of highway systems. Aquí radica la importancia del concepto. Motivation: Minimum Spanning Trees. Costo de los ciclos. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Minimum Spanning Trees

Problem: Connect a set of nodes by a network of minimal total length

Some applications: – Communication networks

– Circuit design

– Layout of highway systems

Aquí radica la importancia del

concepto

Page 2: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Motivation: Minimum Spanning Trees

To minimize the length of a connecting network, it never pays to have cycles.

The resulting connection graph is connected, undirected, and acyclic, i.e., a free tree (sometimes called simply a tree).

This is the minimum spanning tree or MST problem.

Costo de los ciclos

No realmente, porque la posición de la raíz no es significativa.

Page 3: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Formal Definition of MST

Given a connected, undirected, graph G = (V, E), a spanning tree is an acyclic subset of edges T E that connects all the vertices together.

Assuming G is weighted, we define the cost of a spanning tree T to be the sum of edge weights in the spanning tree

w(T) = (u,v)T w(u,v)

A minimum spanning tree (MST) is a spanning tree of minimum weight.

Esto es lo que le da carácter de

árbol

¿Por qué no es un grafo?

Page 4: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Figure1 : Examples of MST

Not only do the edges sum to the same value, but the same set of edge weights appear in the two MSTs. NOTE: An MST may not be unique.

Page 5: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Facts about (Free) Trees

A tree with n vertices has exactly n-1 edges (|E| = |V| - 1)

There exists a unique path between any two vertices of a tree

Adding any edge to a tree creates a unique cycle; breaking any edge on this cycle restores a tree

For details see CLRS Appendix B.5.1 No tiene que ser

necesariamente el mismo árbol incial.

Page 6: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Intuition behind Prim’s Algorithm

Consider the set of vertices S currently part of the tree, and its complement (V-S). We have a cut of the graph and the current set of tree edges A is respected by this cut.

Which edge should we add next? Light edge!

En esto radica la “voracidad” del

algoritmo

Page 7: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Basics of Prim ’s Algorithm

It works by adding leaves on at a time to the current tree. – Start with the root vertex r (it can be any vertex). At any

time, the subset of edges A forms a single tree. S = vertices of A.

– At each step, a light edge connecting a vertex in S to a vertex in V- S is added to the tree.

– The tree grows until it spans all the vertices in V.

Implementation Issues:– How to update the cut efficiently?– How to determine the light edge quickly?

Page 8: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Implementation: Priority Queue

Priority queue implemented using heap can support the following operations in O(lg n) time:– Insert (Q, u, key): Insert u with the key value key in Q– u = Extract_Min(Q): Extract the item with minimum key value in

Q

– Decrease_Key(Q, u, new_key): Decrease the value of u’s key value to new_key

All the vertices that are not in the S (the vertices of the edges in A) reside in a priority queue Q based on a key field. When the algorithm terminates, Q is empty. A = {(v, [v]): v V - {r}}

Page 9: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Example: Prim’s Algorithm

Page 10: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Example: Prim’s Algorithm

Page 11: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Example: Prim’s Algorithm

Page 12: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Example: Prim’s Algorithm

Page 13: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

MST-Prim(G, w, r)

1. Q V[G]2. for each vertex u Q // initialization: O(V) time3. do key[u] 4. key[r] 0 // start at the root5. [r] NIL // set parent of r to be NIL6. while Q // until all vertices in MST7. do u Extract-Min(Q) // vertex with lightest edge8. for each v adj[u]9. do if v Q and w(u,v) < key[v] 10. then [v] u11. key[v] w(u,v) // new lighter edge out of v

12. decrease_Key(Q, v, key[v])

Ver http://www.csharphelp.com/2006/12/graphical-implementation-for-prims-algorithm/

http://www.youtube.com/watch?v=sl6W3_Q4HZohttp://www.youtube.com/watch?v=g05IeI5k8pE&feature=related

Page 14: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Analysis of Prim

Extracting the vertex from the queue: O(lg n)

For each incident edge, decreasing the key of the neighboring vertex: O(lg n) where n = |V|

The other steps are constant time.

The overall running time is, where e = |E| T(n) = uV(lg n + deg(u) lg n) = uV (1+ deg(u)) lg n

= lg n (n + 2e) = O((n + e) lg n)

Essentially same as Kruskal’s: O((n+e) lg n) time

Page 15: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Correctness of Prim

Again, show that every edge added is a safe edge for A

Assume (u, v) is next edge to be added to A. Consider the cut (A, V-A).

– This cut respects A (why?) – and (u, v) is the light edge across the cut (why?)

Thus, by the MST Lemma, (u,v) is safe.

Page 16: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Optimization Problems

In which a set of choices must be made in order to arrive at an optimal (min/max) solution, subject to some constraints. (There may be several solutions to achieve an optimal value.)

Two common techniques:– Dynamic Programming (global)– Greedy Algorithms (local)

Page 17: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Dynamic Programming

Similar to divide-and-conquer, it breaks problems down into smaller problems that are solved recursively.

In contrast to D&C, DP is applicable when the sub-problems are not independent, i.e. when sub-problems share sub-subproblems. It solves every sub-subproblem just once and saves the results in a table to avoid duplicated computation.

Page 18: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Elements of DP Algorithms

Substructure: decompose problem into smaller sub-problems. Express the solution of the original problem in terms of solutions for smaller problems.

Table-structure: Store the answers to the sub-problem in a table, because sub-problem solutions may be used many times.

Bottom-up computation: combine solutions on smaller sub-problems to solve larger sub-problems, and eventually arrive at a solution to the complete problem.

Page 19: Minimum Spanning Trees

UNC Chapel Hill Lin/Foskey/Manocha

Applicability to Optimization Problems

Optimal sub-structure (principle of optimality): for the global problem to be solved optimally, each sub-problem should be solved optimally. This is often violated due to sub-problem overlaps. Often by being “less optimal” on one problem, we may make a big savings on another sub-problem.

Small number of sub-problems: Many NP-hard problems can be formulated as DP problems, but these formulations are not efficient, because the number of sub-problems is exponentially large. Ideally, the number of sub-problems should be at most a polynomial number.