Beruflich Dokumente
Kultur Dokumente
comp-420
w(T ) =
(u,v)T
w(u, v).
Qu tipo de estructura debe ser T para ser acclico y conectar todos los nodos? un rbol (llamado rbol generador)
arbol generador mnimo con un costo de 37. arbol que no es nico. Podemos cambiar por ejemplo (b,c) por (a,h) y tendr el mismo costo.
13.1
Introduction
Por simplicidad supondremos that all the edge weights are tienen pesos distintos w(e) w(e) To keep things simple, Ill assume que todas las aristas distinct: w(e) = w(e ) for any pair of edges e and e Distinct weights guarantee that the minimum spanning tree of the graph para cualquier par. de aristas e y e.
is unique. Without this condition, there may be several dierent minimum spanning trees. For example, if all the edges have weight 1, then every spanning tree is a Pesos distintos garantizan que el MST de una grcaminimum spanning tree with sea nica. weight V 1.
8 10 2 18 12 14 4 26 3 30 16 5
Suppose we are given a connected, undirected, weighted graph. This is a graph G = (V, E) together with a function w : E IR that assigns a weight w(e) to each edge e. For this lecture, well assume that the weights are real numbers. Our task is to nd the minimum spanning tree of G, i.e., the spanning tree T minimizing the function w(T ) = w(e).
Podemos have an algorithm that assumes thesuponga pesos iguales en ciertas aristas en pero If we utilizar un algoritmo que edge weights are unique, we can still use it on graphs where mtodo de desempate. con un multiple edges have the same weight, as long as we have a consistent method for breaking
ties. One way to break ties consistently is to use the following algorithm in place of a simple comparison. ShorterEdge takes as input four integers i, j, k, l, and decides which of the two Un ejemploand (k, l) has smaller weight. edges (i, j) de mtodo de desempate es SHORTEREDGE(i,j,k,l) que decide, entre
dos
14
26
If we have an algorithm that assumes the edge weights are unique, we can still use it on graph ere multiple edges have the same weight, as long as we have a consistent method for breakin . One way to break ties consistently is to use the following algorithm in place of a simp mparison. ShorterEdge takes as input four integers i, j, k, l, and decides which of the tw es (i, j) and (k, l) has smaller weight. ShorterEdge(i, j, k, l) if w(i, j) < w(k, l) return (i, j) if w(i, j) > w(k, l) return (k, l) if min(i, j) < min(k, l) return (i, j) if min(i, j) > min(k, l) return (k, l) if max(i, j) < max(k, l) return (i, j) if max(i,j) < max(k,l) return (k, l)
ere are several dierent ways to compute minimum spanning trees, but really they are all in nces of the following generic algorithm. The situation is similar to the previous lecture, where w that depth-rst search and breadth-rst search were both instances of a single generic traversa orithm.
Inicialmente, la subgrca A consta de n rboles de un nodo cada uno. El algoritmo genrico une los rboles agregando ciertas aristas entre esos nodos. Cuando el algoritmo se detiene, A consta de un slo arbol de n vrtices: el rbol generador mnimo.
and every component of F is a minimum spanning A induce dos Initially, de aristas: El bosque generador intermedio tree of its vertices. tipos F consists of n one-node trees. The generic MST algorithm merges trees together by adding certain edges between them. When the algorithm halts, F consists of a single n-node tree, which must be the minimum spanning tree. Obviously, we have to beno son aristas edges A pero the evolving forest, extremos aristas inservibles si careful about which de we add to ambos puntos since not every edge is in the eventual minimum spanning tree. These encuentran en el induces two special types of edges. A. edge is useless if it is intermediate spanning forest F mismo componente de An not an edge of F , but both its endpoints are in the same component of F . For each component of F , we associate a safe edgethe minimum-weight edge with exactly one endpoint in that component. 1 aristas seguras si sus puntos extremos conectan, con el costo mnimo Dierent components might or might not have dierent safe edges. Some edges are neither safe nor uselesswe call these edges undecided. A. dos componentes de All minimum spanning tree algorithms are based on two simple observations.
Componentes distintas pueden every tener aristas seguras Lemma 1. The minimum spanning tree contains o no safe edge and no useless edges.
diferentes.
Proof: Let T be the minimum spanning tree. Suppose F has a bad component whose safe edge Algunas aristas pueden no ser ni servibles ni seguras, las least e = (u, v) is not in T . Since T is connected, it contains a unique path from u to v, and atllamaremos one edge e on this path has exactly one endpoint in the bad component. Removing e from the indecisas. minimum spanning tree and adding e gives us a new spanning tree. Since e is the bad components safe edge, we have w(e ) > w(e), so the the new spanning tree has smaller total weight than T . But thisMST contienethe minimum spanning tree.seguras contain every safe edge. inservible. Un is impossibleT is todas las aristas So T must y ninguna arista Adding any useless edge to F would introduce a cycle.
e v e
Proving that every safe edge is in the minimum spanning tree. The bad component of F is highlighted.
CS 373
and every component of F is a minimum spanning tree of its vertices. Initially, F consists of n one-node trees. The generic MST algorithm merges trees together by adding certain edges between them. When the algorithm halts, F consists of a single n-node tree, which must be the minimum spanning tree. Obviously, we have to be careful about which edges we add to the evolving forest, since not every edge is in the eventual minimum spanning tree. The intermediate spanning forest F induces two special types of edges. An edge is useless if it is not an edge El we associateof F ,genrico minimum-weightthe same componentuna. Formscomponent ofseguras algoritmo but both its endpoints arerepetidamenteone endpoint in that component. 1, agrega in edge with exactly of F o each aristas F a safe edgethe bosque A que evoluciona. not have dierent safe edges. Some edges are neither safe nor Dierent components might or might uselesswe call these edges undecided. All minimum spanning tree algorithms are based on two simple observations.
Fall 2002
al
Cuando agregamos nuevas aristas a A, algunas aristas indecisas se Lemma 1. conviertenThe minimum spanning tree en inservibles. and no useless edges. en seguras, otras contains every safe edge
Proof: Let T be the minimum spanning tree. Suppose F has a bad component whose safe edge e = especicar Since T is connected, contains a unique path from decidir at least Para (u, v) is not in T .un algoritmo enit particular debemos u to v, and qu aristas one edge e on this path has exactly one endpoint in the bad component. Removing e from the agregar y cmo identicargives us a new spanning segurase e the bad components cada minimum spanning tree and adding e nuevas aristas tree. Since is inservibles en safe edge, we have w(e ) > w(e), so the the new spanning tree has smaller total weight than T . iteracinis del algoritmo. minimum spanning tree. So T must contain every safe edge. But this impossibleT is the Adding any useless edge to F would introduce a cycle.
e v e
Proving that every safe edge is in the minimum spanning tree. The bad component of F is highlighted.
So our generic minimum spanning tree algorithm repeatedly adds one or more safe edges to
S V S
S V S
Decimos que la arista (u,v) E cruza el corte (S, V-S) si uno de sus extremos est en S y el otro en V-S. Qu arista cruza el corte aqu?
Sea G=(V,E) una grca conectada, no dirigida con una funcin real w de costos denida en E. Sea A un subconjunto de E incluido en un MST para G, sea (S,V-S) cualquier corte de G que respete A, y sea (u,v) una arista clara que cruce (S,V-S). Entonces, la arista (u,v) es segura para A.
Sea T un MST que incluye A y supongamos que T no contiene a la arista clara (u,v). Queremos construir otro MST, T que incluya A {(u,v)} mostrando que (u,v) es una arista segura. La arista (u,v) forma un cclo con las aristas del camino p desde u hasta v en T. Ya que u y v estn en lados opuestos del corte (S,V-S), hay al menos una arista en T en el camino p que tambin cruza el corte. (x,y) no est en A porque sabemos que el corte respeta A.
Ya que (x,y) est en el nico camino p desde u hasta v en T, remover (x,y) desconecta T en dos componentes. Agregar (u,v) le reconecta para formar un nuevo MST: T = T-{(x,y)} {(u,v)}.
Problema concreto de ingeniera que se convirti en un modelo de problema para la optimizacin combinatoria. Es el algoritmo ms antiguo y posiblemente el ms simple para encontrar MST. Redescubierto por Choquet, Florek, Lukaziewicz, Perkal, Steinhaus, Zubrzycki y Sollin.
CS 373
Fall 2002
Bor Add all the safe edges recurse. Boruvka:uvka: Add all thesafe edges andand recurse.
8 10 2 18 12 14
18
5
2
5 10 3 30 14 16 18 12 14 26
12
30
4
16
26
18
12
eginning of each phase of the Boruvka algorithm, each component elects a FindSafeEdges(V, E): Una vez elegidos los lderes encontramos las aristas seguras para cada componente, e. The por fuerza bruta y estas son agregadas a A. isfor each leader v search of F ; th simplest way to hold these elections a depth-rst Boruvka(V, that safe(v) leaders are elected, any component is E): components leader. Once the
El algoritmo elige arbitrariamente un vrtice lder. At the beginning of each phase of the Boruvka algorithm, each component elects an arbitrary Boruvkas algorithm run encontrar a este graph. Thick edges are in en. Lanode. The simplest way to holdthe example ldes depth-rst search of F ; F rst node manera ms simple para on these elections is a es con una bsqueda the leader Arrows point along isA. Elcomponents leader. OnceDashed edges are useless.nd the each components que edge. the cualquier componente profundidad (DFS) en that primer nodo safe visitamos enleaders are elected, we ser we visit in any component el lder del component, safe edges for each componente.essentially by brute force. Finally, we add these safe edges to F .
Boruvkas algorithm run on the example graph. Thick edges are in F . Arrows point along each components safe edge. Dashed edges are useless. 26 26
14
18
12 14
30
16
18
12 14
Boruvkas algorithm run on the example graph. Thick edges are in F . Arrows point along each components safe edge. Dashed edges are useless.
At the beginning of each phase of the Boruvka algorithm, each component elects an arbitr Bor uvka(V, E) ader node. The simplest way to hold these elections is a depth-rst search of F ; the rst n 1 A = (V, ) visit in any component is that components leader. Once the leaders are elected, we nd 2 while component, than one by brute force. Finally, we add these safe edges to F fe edges for each A has more essentially component
3 choose leaders using DFS 4 FindSafeEdges(V, E) 5 for each leader v 6 add safe(v) a A Boruvka(V, E):
F = (V, ) while F has more than one component choose leaders using DFS FindSafeEdges(V, E) for each leader v add safe(v) to F
FindSafeEdges(V, E): for each leader v safe(v) for each edge (u, v) E u leader(u) v leader(v) if u = v if w(u, v) < w(safe(u)) safe(u) (u, v) if w(u, v) < w(safe(v)) safe(v) (u, v)
Each call to FindSafeEdges takes O(E) time, since it examines every edge. Since the grap