+ All Categories
Home > Documents > Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

Date post: 29-Oct-2021
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
133
Árboles generadores mínimos (MST) comp-420 Tuesday, September 24, 13
Transcript
Page 1: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)comp-420

Tuesday, September 24, 13

Page 2: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

Tuesday, September 24, 13

Page 3: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Sea G=(V,E) una gráfica conectada y no-dirigida con V vértices y E aristas.

Tuesday, September 24, 13

Page 4: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Sea G=(V,E) una gráfica conectada y no-dirigida con V vértices y E aristas.

• Cada arista (u,v)∈E tiene un peso w(u,v), que es el costo de conectar u y v.

Tuesday, September 24, 13

Page 5: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Sea G=(V,E) una gráfica conectada y no-dirigida con V vértices y E aristas.

• Cada arista (u,v)∈E tiene un peso w(u,v), que es el costo de conectar u y v.

• La meta es encontrar un subconjunto acíclico T⊆E que conecte todos los vértices y que minimice el costo total

Tuesday, September 24, 13

Page 6: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Sea G=(V,E) una gráfica conectada y no-dirigida con V vértices y E aristas.

• Cada arista (u,v)∈E tiene un peso w(u,v), que es el costo de conectar u y v.

• La meta es encontrar un subconjunto acíclico T⊆E que conecte todos los vértices y que minimice el costo total

w(T ) =∑

(u,v)∈T

w(u, v).

Tuesday, September 24, 13

Page 7: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Sea G=(V,E) una gráfica conectada y no-dirigida con V vértices y E aristas.

• Cada arista (u,v)∈E tiene un peso w(u,v), que es el costo de conectar u y v.

• La meta es encontrar un subconjunto acíclico T⊆E que conecte todos los vértices y que minimice el costo total

• ¿Qué tipo de estructura debe ser T para ser acíclico y conectar todos los nodos?

w(T ) =∑

(u,v)∈T

w(u, v).

Tuesday, September 24, 13

Page 8: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Sea G=(V,E) una gráfica conectada y no-dirigida con V vértices y E aristas.

• Cada arista (u,v)∈E tiene un peso w(u,v), que es el costo de conectar u y v.

• La meta es encontrar un subconjunto acíclico T⊆E que conecte todos los vértices y que minimice el costo total

• ¿Qué tipo de estructura debe ser T para ser acíclico y conectar todos los nodos?

• un árbol (llamado árbol generador)

w(T ) =∑

(u,v)∈T

w(u, v).

Tuesday, September 24, 13

Page 9: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Sea G=(V,E) una gráfica conectada y no-dirigida con V vértices y E aristas.

• Cada arista (u,v)∈E tiene un peso w(u,v), que es el costo de conectar u y v.

• La meta es encontrar un subconjunto acíclico T⊆E que conecte todos los vértices y que minimice el costo total

• ¿Qué tipo de estructura debe ser T para ser acíclico y conectar todos los nodos?

• un árbol (llamado árbol generador)

• En inglés “minimum spanning trees”.

w(T ) =∑

(u,v)∈T

w(u, v).

Tuesday, September 24, 13

Page 10: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

Tuesday, September 24, 13

Page 11: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

b c d

e

fg

i

4

8 7

9

10

1442

6

1 2

7

11

8h

a

Tuesday, September 24, 13

Page 12: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• arbol generador mínimo con un costo de 37.

b c d

e

fg

i

4

8 7

9

10

1442

6

1 2

7

11

8h

a

Tuesday, September 24, 13

Page 13: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• arbol generador mínimo con un costo de 37.

• arbol que no es único. Podemos cambiar por ejemplo (b,c) por (a,h) y tendrá el mismo costo.

b c d

e

fg

i

4

8 7

9

10

1442

6

1 2

7

11

8h

a

Tuesday, September 24, 13

Page 14: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

Tuesday, September 24, 13

Page 15: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Por simplicidad supondremos que todas las aristas tienen pesos distintos w(e) ≠ w(e’) para cualquier par de aristas e y e’.

Tuesday, September 24, 13

Page 16: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Por simplicidad supondremos que todas las aristas tienen pesos distintos w(e) ≠ w(e’) para cualquier par de aristas e y e’.

• Pesos distintos garantizan que el MST de una gráfica sea único.

Tuesday, September 24, 13

Page 17: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Por simplicidad supondremos que todas las aristas tienen pesos distintos w(e) ≠ w(e’) para cualquier par de aristas e y e’.

• Pesos distintos garantizan que el MST de una gráfica sea único.

CS 373 Lecture 13: Minimum Spanning Trees Fall 2002

13 Minimum Spanning Trees (October 29)

13.1 Introduction

Suppose we are given a connected, undirected, weighted graph. This is a graph G = (V,E) togetherwith a function w : E ⇧ IR that assigns a weight w(e) to each edge e. For this lecture, we’ll assumethat the weights are real numbers. Our task is to find the minimum spanning tree of G, i.e., thespanning tree T minimizing the function

w(T ) =�

e⇥T

w(e).

To keep things simple, I’ll assume that all the edge weights are distinct: w(e) ⇤= w(e �) for anypair of edges e and e�. Distinct weights guarantee that the minimum spanning tree of the graphis unique. Without this condition, there may be several di�erent minimum spanning trees. Forexample, if all the edges have weight 1, then every spanning tree is a minimum spanning tree withweight V ⇥ 1.

8 5

10

2 3

18 16

12

14

30

4 26

A weighted graph and its minimum spanning tree.

If we have an algorithm that assumes the edge weights are unique, we can still use it on graphswhere multiple edges have the same weight, as long as we have a consistent method for breakingties. One way to break ties consistently is to use the following algorithm in place of a simplecomparison. ShorterEdge takes as input four integers i, j, k, l, and decides which of the twoedges (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)

13.2 The Only MST Algorithm

There are several di�erent ways to compute minimum spanning trees, but really they are all in-stances of the following generic algorithm. The situation is similar to the previous lecture, where wesaw that depth-first search and breadth-first search were both instances of a single generic traversalalgorithm.

The generic MST algorithm maintains an acyclic subgraph F of the input graph G, which wewill call an intermediate spanning forest. F is a subgraph of the minimum spanning tree of G,

1

Tuesday, September 24, 13

Page 18: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Por simplicidad supondremos que todas las aristas tienen pesos distintos w(e) ≠ w(e’) para cualquier par de aristas e y e’.

• Pesos distintos garantizan que el MST de una gráfica sea único.

• Podemos utilizar un algoritmo que suponga pesos iguales en ciertas aristas pero con un método de desempate.

CS 373 Lecture 13: Minimum Spanning Trees Fall 2002

13 Minimum Spanning Trees (October 29)

13.1 Introduction

Suppose we are given a connected, undirected, weighted graph. This is a graph G = (V,E) togetherwith a function w : E ⇧ IR that assigns a weight w(e) to each edge e. For this lecture, we’ll assumethat the weights are real numbers. Our task is to find the minimum spanning tree of G, i.e., thespanning tree T minimizing the function

w(T ) =�

e⇥T

w(e).

To keep things simple, I’ll assume that all the edge weights are distinct: w(e) ⇤= w(e �) for anypair of edges e and e�. Distinct weights guarantee that the minimum spanning tree of the graphis unique. Without this condition, there may be several di�erent minimum spanning trees. Forexample, if all the edges have weight 1, then every spanning tree is a minimum spanning tree withweight V ⇥ 1.

8 5

10

2 3

18 16

12

14

30

4 26

A weighted graph and its minimum spanning tree.

If we have an algorithm that assumes the edge weights are unique, we can still use it on graphswhere multiple edges have the same weight, as long as we have a consistent method for breakingties. One way to break ties consistently is to use the following algorithm in place of a simplecomparison. ShorterEdge takes as input four integers i, j, k, l, and decides which of the twoedges (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)

13.2 The Only MST Algorithm

There are several di�erent ways to compute minimum spanning trees, but really they are all in-stances of the following generic algorithm. The situation is similar to the previous lecture, where wesaw that depth-first search and breadth-first search were both instances of a single generic traversalalgorithm.

The generic MST algorithm maintains an acyclic subgraph F of the input graph G, which wewill call an intermediate spanning forest. F is a subgraph of the minimum spanning tree of G,

1

Tuesday, September 24, 13

Page 19: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Por simplicidad supondremos que todas las aristas tienen pesos distintos w(e) ≠ w(e’) para cualquier par de aristas e y e’.

• Pesos distintos garantizan que el MST de una gráfica sea único.

• Podemos utilizar un algoritmo que suponga pesos iguales en ciertas aristas pero con un método de desempate.

• Un ejemplo de método de desempate es SHORTEREDGE(i,j,k,l) que decide, entre dos aristas (i,j) y (k,l) cuál tiene el menor peso.

CS 373 Lecture 13: Minimum Spanning Trees Fall 2002

13 Minimum Spanning Trees (October 29)

13.1 Introduction

Suppose we are given a connected, undirected, weighted graph. This is a graph G = (V,E) togetherwith a function w : E ⇧ IR that assigns a weight w(e) to each edge e. For this lecture, we’ll assumethat the weights are real numbers. Our task is to find the minimum spanning tree of G, i.e., thespanning tree T minimizing the function

w(T ) =�

e⇥T

w(e).

To keep things simple, I’ll assume that all the edge weights are distinct: w(e) ⇤= w(e �) for anypair of edges e and e�. Distinct weights guarantee that the minimum spanning tree of the graphis unique. Without this condition, there may be several di�erent minimum spanning trees. Forexample, if all the edges have weight 1, then every spanning tree is a minimum spanning tree withweight V ⇥ 1.

8 5

10

2 3

18 16

12

14

30

4 26

A weighted graph and its minimum spanning tree.

If we have an algorithm that assumes the edge weights are unique, we can still use it on graphswhere multiple edges have the same weight, as long as we have a consistent method for breakingties. One way to break ties consistently is to use the following algorithm in place of a simplecomparison. ShorterEdge takes as input four integers i, j, k, l, and decides which of the twoedges (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)

13.2 The Only MST Algorithm

There are several di�erent ways to compute minimum spanning trees, but really they are all in-stances of the following generic algorithm. The situation is similar to the previous lecture, where wesaw that depth-first search and breadth-first search were both instances of a single generic traversalalgorithm.

The generic MST algorithm maintains an acyclic subgraph F of the input graph G, which wewill call an intermediate spanning forest. F is a subgraph of the minimum spanning tree of G,

1

Tuesday, September 24, 13

Page 20: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

CS 373 Lecture 13: Minimum Spanning Trees Fall 2002

13 Minimum Spanning Trees (October 29)

13.1 Introduction

Suppose we are given a connected, undirected, weighted graph. This is a graph G = (V,E) togetherwith a function w : E ⇧ IR that assigns a weight w(e) to each edge e. For this lecture, we’ll assumethat the weights are real numbers. Our task is to find the minimum spanning tree of G, i.e., thespanning tree T minimizing the function

w(T ) =�

e⇥T

w(e).

To keep things simple, I’ll assume that all the edge weights are distinct: w(e) ⇤= w(e �) for anypair of edges e and e�. Distinct weights guarantee that the minimum spanning tree of the graphis unique. Without this condition, there may be several di�erent minimum spanning trees. Forexample, if all the edges have weight 1, then every spanning tree is a minimum spanning tree withweight V ⇥ 1.

8 5

10

2 3

18 16

12

14

30

4 26

A weighted graph and its minimum spanning tree.

If we have an algorithm that assumes the edge weights are unique, we can still use it on graphswhere multiple edges have the same weight, as long as we have a consistent method for breakingties. One way to break ties consistently is to use the following algorithm in place of a simplecomparison. ShorterEdge takes as input four integers i, j, k, l, and decides which of the twoedges (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)

13.2 The Only MST Algorithm

There are several di�erent ways to compute minimum spanning trees, but really they are all in-stances of the following generic algorithm. The situation is similar to the previous lecture, where wesaw that depth-first search and breadth-first search were both instances of a single generic traversalalgorithm.

The generic MST algorithm maintains an acyclic subgraph F of the input graph G, which wewill call an intermediate spanning forest. F is a subgraph of the minimum spanning tree of G,

1

>

Tuesday, September 24, 13

Page 21: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

Tuesday, September 24, 13

Page 22: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• ¿Cómo encontrarían el árbol generador mínimo?

Tuesday, September 24, 13

Page 23: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• ¿Cómo encontrarían el árbol generador mínimo?

• IDEA: algoritmo de fuerza bruta.

Tuesday, September 24, 13

Page 24: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• ¿Cómo encontrarían el árbol generador mínimo?

• IDEA: algoritmo de fuerza bruta.

• calcular todos los árboles generadores.

Tuesday, September 24, 13

Page 25: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• ¿Cómo encontrarían el árbol generador mínimo?

• IDEA: algoritmo de fuerza bruta.

• calcular todos los árboles generadores.

• encontrar el mínimo.

Tuesday, September 24, 13

Page 26: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• ¿Cómo encontrarían el árbol generador mínimo?

• IDEA: algoritmo de fuerza bruta.

• calcular todos los árboles generadores.

• encontrar el mínimo.

• PROBLEMAS:

Tuesday, September 24, 13

Page 27: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• ¿Cómo encontrarían el árbol generador mínimo?

• IDEA: algoritmo de fuerza bruta.

• calcular todos los árboles generadores.

• encontrar el mínimo.

• PROBLEMAS:

• no es fácil de implementar.

Tuesday, September 24, 13

Page 28: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• ¿Cómo encontrarían el árbol generador mínimo?

• IDEA: algoritmo de fuerza bruta.

• calcular todos los árboles generadores.

• encontrar el mínimo.

• PROBLEMAS:

• no es fácil de implementar.

• pueden ser muchísimos árboles generadores.

Tuesday, September 24, 13

Page 29: Árboles generadores mínimos (MST)

muchos ST

Tuesday, September 24, 13

Page 30: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

Tuesday, September 24, 13

Page 31: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Existen varias maneras de calcular el MST pero todas son instancias de un algoritmos genérico.

Tuesday, September 24, 13

Page 32: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Existen varias maneras de calcular el MST pero todas son instancias de un algoritmos genérico.

• La situación es similar a la de los algoritmos de recorridos de gráficas (dfs y bfs).

Tuesday, September 24, 13

Page 33: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Existen varias maneras de calcular el MST pero todas son instancias de un algoritmos genérico.

• La situación es similar a la de los algoritmos de recorridos de gráficas (dfs y bfs).

• El algoritmo genérico para encontrar el MST mantiene una subgráfica acíclica A de la gráfica de entrada G.

Tuesday, September 24, 13

Page 34: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Existen varias maneras de calcular el MST pero todas son instancias de un algoritmos genérico.

• La situación es similar a la de los algoritmos de recorridos de gráficas (dfs y bfs).

• El algoritmo genérico para encontrar el MST mantiene una subgráfica acíclica A de la gráfica de entrada G.

• Esta subgráfica se llama bósque generador intermedio (intermediate spanning forest)

Tuesday, September 24, 13

Page 35: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Existen varias maneras de calcular el MST pero todas son instancias de un algoritmos genérico.

• La situación es similar a la de los algoritmos de recorridos de gráficas (dfs y bfs).

• El algoritmo genérico para encontrar el MST mantiene una subgráfica acíclica A de la gráfica de entrada G.

• Esta subgráfica se llama bósque generador intermedio (intermediate spanning forest)

• A es una subgráfica del árbol generador mínimo de G.

Tuesday, September 24, 13

Page 36: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Existen varias maneras de calcular el MST pero todas son instancias de un algoritmos genérico.

• La situación es similar a la de los algoritmos de recorridos de gráficas (dfs y bfs).

• El algoritmo genérico para encontrar el MST mantiene una subgráfica acíclica A de la gráfica de entrada G.

• Esta subgráfica se llama bósque generador intermedio (intermediate spanning forest)

• A es una subgráfica del árbol generador mínimo de G.

• Cada componente de A es un árbol generador mínimo de sus vértices.

Tuesday, September 24, 13

Page 37: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

Tuesday, September 24, 13

Page 38: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Inicialmente, la subgráfica A consta de n árboles de un nodo cada uno.

Tuesday, September 24, 13

Page 39: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Inicialmente, la subgráfica A consta de n árboles de un nodo cada uno.

• El algoritmo genérico une los árboles agregando ciertas aristas entre esos nodos.

Tuesday, September 24, 13

Page 40: Árboles generadores mínimos (MST)

Árboles generadores mínimos (MST)

• Inicialmente, la subgráfica A consta de n árboles de un nodo cada uno.

• El algoritmo genérico une los árboles agregando ciertas aristas entre esos nodos.

• Cuando el algoritmo se detiene, A consta de un sólo arbol de n vértices: el árbol generador mínimo.

Tuesday, September 24, 13

Page 41: Árboles generadores mínimos (MST)

MST: algoritmo genérico

Tuesday, September 24, 13

Page 42: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Supongamos una gráfica conectada y no-dirigida G=(V,E) con una función de peso w: E→R, que asigna un peso w(e) a cada arista e.

Tuesday, September 24, 13

Page 43: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Supongamos una gráfica conectada y no-dirigida G=(V,E) con una función de peso w: E→R, que asigna un peso w(e) a cada arista e.

• Queremos encontrar el arbol mínimo generador para G.

Tuesday, September 24, 13

Page 44: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Supongamos una gráfica conectada y no-dirigida G=(V,E) con una función de peso w: E→R, que asigna un peso w(e) a cada arista e.

• Queremos encontrar el arbol mínimo generador para G.

• El algoritmo maneja una serie de aristas (subgráfica de G) A, manteniendo la invariante al cíclo siguiente:

Tuesday, September 24, 13

Page 45: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Supongamos una gráfica conectada y no-dirigida G=(V,E) con una función de peso w: E→R, que asigna un peso w(e) a cada arista e.

• Queremos encontrar el arbol mínimo generador para G.

• El algoritmo maneja una serie de aristas (subgráfica de G) A, manteniendo la invariante al cíclo siguiente:

Antes de cada iteración, A es un subconjunto de un MST

Tuesday, September 24, 13

Page 46: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Supongamos una gráfica conectada y no-dirigida G=(V,E) con una función de peso w: E→R, que asigna un peso w(e) a cada arista e.

• Queremos encontrar el arbol mínimo generador para G.

• El algoritmo maneja una serie de aristas (subgráfica de G) A, manteniendo la invariante al cíclo siguiente:

Antes de cada iteración, A es un subconjunto de un MST

• En cada paso determinamos la arista (u,v) que pueda agregarse sin violar esta invariante: A ∪ {(u,v)} será también un subconjunto de MST.

Tuesday, September 24, 13

Page 47: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Supongamos una gráfica conectada y no-dirigida G=(V,E) con una función de peso w: E→R, que asigna un peso w(e) a cada arista e.

• Queremos encontrar el arbol mínimo generador para G.

• El algoritmo maneja una serie de aristas (subgráfica de G) A, manteniendo la invariante al cíclo siguiente:

Antes de cada iteración, A es un subconjunto de un MST

• En cada paso determinamos la arista (u,v) que pueda agregarse sin violar esta invariante: A ∪ {(u,v)} será también un subconjunto de MST.

• La arista (u,v) se conoce como arista segura o “safe edge”.

Tuesday, September 24, 13

Page 48: Árboles generadores mínimos (MST)

MST: algoritmo genérico

Tuesday, September 24, 13

Page 49: Árboles generadores mínimos (MST)

MST: algoritmo genérico• El bosque generador intermedio A induce dos tipos de aristas:

Tuesday, September 24, 13

Page 50: Árboles generadores mínimos (MST)

MST: algoritmo genérico• El bosque generador intermedio A induce dos tipos de aristas:

• aristas inservibles si no son aristas de A pero ambos puntos extremos se encuentran en el mismo componente de A.

Tuesday, September 24, 13

Page 51: Árboles generadores mínimos (MST)

MST: algoritmo genérico• El bosque generador intermedio A induce dos tipos de aristas:

• aristas inservibles si no son aristas de A pero ambos puntos extremos se encuentran en el mismo componente de A.

• aristas seguras si sus puntos extremos conectan, con el costo mínimo dos componentes de A.

Tuesday, September 24, 13

Page 52: Árboles generadores mínimos (MST)

MST: algoritmo genérico• El bosque generador intermedio A induce dos tipos de aristas:

• aristas inservibles si no son aristas de A pero ambos puntos extremos se encuentran en el mismo componente de A.

• aristas seguras si sus puntos extremos conectan, con el costo mínimo dos componentes de A.

• Componentes distintas pueden o no tener aristas seguras diferentes.

Tuesday, September 24, 13

Page 53: Árboles generadores mínimos (MST)

MST: algoritmo genérico• El bosque generador intermedio A induce dos tipos de aristas:

• aristas inservibles si no son aristas de A pero ambos puntos extremos se encuentran en el mismo componente de A.

• aristas seguras si sus puntos extremos conectan, con el costo mínimo dos componentes de A.

• Componentes distintas pueden o no tener aristas seguras diferentes.

• Algunas aristas pueden no ser ni servibles ni seguras, las llamaremos indecisas.

Tuesday, September 24, 13

Page 54: Árboles generadores mínimos (MST)

MST: algoritmo genérico• El bosque generador intermedio A induce dos tipos de aristas:

• aristas inservibles si no son aristas de A pero ambos puntos extremos se encuentran en el mismo componente de A.

• aristas seguras si sus puntos extremos conectan, con el costo mínimo dos componentes de A.

• Componentes distintas pueden o no tener aristas seguras diferentes.

• Algunas aristas pueden no ser ni servibles ni seguras, las llamaremos indecisas.

• Un MST contiene todas las aristas seguras y ninguna arista inservible.

Tuesday, September 24, 13

Page 55: Árboles generadores mínimos (MST)

MST: algoritmo genérico• El bosque generador intermedio A induce dos tipos de aristas:

• aristas inservibles si no son aristas de A pero ambos puntos extremos se encuentran en el mismo componente de A.

• aristas seguras si sus puntos extremos conectan, con el costo mínimo dos componentes de A.

• Componentes distintas pueden o no tener aristas seguras diferentes.

• Algunas aristas pueden no ser ni servibles ni seguras, las llamaremos indecisas.

• Un MST contiene todas las aristas seguras y ninguna arista inservible.

CS 373 Lecture 13: Minimum Spanning Trees Fall 2002

and every component of F is a minimum spanning tree of its vertices. Initially, F consists of none-node trees. The generic MST algorithm merges trees together by adding certain edges betweenthem. When the algorithm halts, F consists of a single n-node tree, which must be the minimumspanning 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 isnot an edge of F , but both its endpoints are in the same component of F . For each component of F ,we associate a safe edge—the minimum-weight edge with exactly one endpoint in that component.1

Di�erent components might or might not have di�erent safe edges. Some edges are neither safe noruseless—we call these edges undecided.

All minimum spanning tree algorithms are based on two simple observations.

Lemma 1. The minimum spanning tree contains every safe edge and no useless edges.

Proof: Let T be the minimum spanning tree. Suppose F has a ‘bad’ component whose safe edgee = (u, v) is not in T . Since T is connected, it contains a unique path from u to v, and at leastone edge e� on this path has exactly one endpoint in the bad component. Removing e� from theminimum spanning tree and adding e gives us a new spanning tree. Since e is the bad component’ssafe edge, we have w(e�) > w(e), so the the new spanning tree has smaller total weight than T .But this is impossible—T is the minimum spanning tree. So T must contain every safe edge.

Adding any useless edge to F would introduce a cycle. �

u

v

e

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 tothe evolving forest F . Whenever we add new edges to F , some undecided edges become safe, andothers become useless. To specify a particular algorithm, we must decide which safe edges to add,and how to identify new safe and new useless edges, at each iteration of our generic template.

13.3 Boruvka’s Algorithm

The oldest and possibly simplest minimum spanning tree algorithm was discovered by Boruvka in1926, long before computers even existed, and practically before the invention of graph theory!2 Thealgorithm was rediscovered by Choquet in 1938; again by Florek, Lukaziewicz, Perkal, Stienhaus,and Zubrzycki in 1951; and again by Sollin some time in the early 1960s.

The Boruvka/Choquet/Florek/Lukaziewicz/Perkal/Stienhaus/Zubrzycki/Sollin algorithm canbe summarized in one line:

1This is actually a special case of a more general definition: For any partition of F into two subforests, theminimum-weight edge with one endpoint in each subforest is light. A few minimum spanning tree algorithms requirethis more general definition, but we won’t talk about them here.

2The first book on graph theory, written by D. Konig, was published in 1936. Leonard Euler published his famoustheorem about the bridges of Konigsburg (HW3, problem 2) in 1736. Konigsburg was not named after that Konig.

2

Tuesday, September 24, 13

Page 56: Árboles generadores mínimos (MST)

MST: algoritmo genéricoCS 373 Lecture 13: Minimum Spanning Trees Fall 2002

and every component of F is a minimum spanning tree of its vertices. Initially, F consists of none-node trees. The generic MST algorithm merges trees together by adding certain edges betweenthem. When the algorithm halts, F consists of a single n-node tree, which must be the minimumspanning 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 isnot an edge of F , but both its endpoints are in the same component of F . For each component of F ,we associate a safe edge—the minimum-weight edge with exactly one endpoint in that component.1

Di�erent components might or might not have di�erent safe edges. Some edges are neither safe noruseless—we call these edges undecided.

All minimum spanning tree algorithms are based on two simple observations.

Lemma 1. The minimum spanning tree contains every safe edge and no useless edges.

Proof: Let T be the minimum spanning tree. Suppose F has a ‘bad’ component whose safe edgee = (u, v) is not in T . Since T is connected, it contains a unique path from u to v, and at leastone edge e� on this path has exactly one endpoint in the bad component. Removing e� from theminimum spanning tree and adding e gives us a new spanning tree. Since e is the bad component’ssafe edge, we have w(e�) > w(e), so the the new spanning tree has smaller total weight than T .But this is impossible—T is the minimum spanning tree. So T must contain every safe edge.

Adding any useless edge to F would introduce a cycle. �

u

v

e

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 tothe evolving forest F . Whenever we add new edges to F , some undecided edges become safe, andothers become useless. To specify a particular algorithm, we must decide which safe edges to add,and how to identify new safe and new useless edges, at each iteration of our generic template.

13.3 Boruvka’s Algorithm

The oldest and possibly simplest minimum spanning tree algorithm was discovered by Boruvka in1926, long before computers even existed, and practically before the invention of graph theory!2 Thealgorithm was rediscovered by Choquet in 1938; again by Florek, Lukaziewicz, Perkal, Stienhaus,and Zubrzycki in 1951; and again by Sollin some time in the early 1960s.

The Boruvka/Choquet/Florek/Lukaziewicz/Perkal/Stienhaus/Zubrzycki/Sollin algorithm canbe summarized in one line:

1This is actually a special case of a more general definition: For any partition of F into two subforests, theminimum-weight edge with one endpoint in each subforest is light. A few minimum spanning tree algorithms requirethis more general definition, but we won’t talk about them here.

2The first book on graph theory, written by D. Konig, was published in 1936. Leonard Euler published his famoustheorem about the bridges of Konigsburg (HW3, problem 2) in 1736. Konigsburg was not named after that Konig.

2

Tuesday, September 24, 13

Page 57: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• El algoritmo genérico agrega repetidamente una o más aristas seguras al bosque A que evoluciona.

CS 373 Lecture 13: Minimum Spanning Trees Fall 2002

and every component of F is a minimum spanning tree of its vertices. Initially, F consists of none-node trees. The generic MST algorithm merges trees together by adding certain edges betweenthem. When the algorithm halts, F consists of a single n-node tree, which must be the minimumspanning 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 isnot an edge of F , but both its endpoints are in the same component of F . For each component of F ,we associate a safe edge—the minimum-weight edge with exactly one endpoint in that component.1

Di�erent components might or might not have di�erent safe edges. Some edges are neither safe noruseless—we call these edges undecided.

All minimum spanning tree algorithms are based on two simple observations.

Lemma 1. The minimum spanning tree contains every safe edge and no useless edges.

Proof: Let T be the minimum spanning tree. Suppose F has a ‘bad’ component whose safe edgee = (u, v) is not in T . Since T is connected, it contains a unique path from u to v, and at leastone edge e� on this path has exactly one endpoint in the bad component. Removing e� from theminimum spanning tree and adding e gives us a new spanning tree. Since e is the bad component’ssafe edge, we have w(e�) > w(e), so the the new spanning tree has smaller total weight than T .But this is impossible—T is the minimum spanning tree. So T must contain every safe edge.

Adding any useless edge to F would introduce a cycle. �

u

v

e

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 tothe evolving forest F . Whenever we add new edges to F , some undecided edges become safe, andothers become useless. To specify a particular algorithm, we must decide which safe edges to add,and how to identify new safe and new useless edges, at each iteration of our generic template.

13.3 Boruvka’s Algorithm

The oldest and possibly simplest minimum spanning tree algorithm was discovered by Boruvka in1926, long before computers even existed, and practically before the invention of graph theory!2 Thealgorithm was rediscovered by Choquet in 1938; again by Florek, Lukaziewicz, Perkal, Stienhaus,and Zubrzycki in 1951; and again by Sollin some time in the early 1960s.

The Boruvka/Choquet/Florek/Lukaziewicz/Perkal/Stienhaus/Zubrzycki/Sollin algorithm canbe summarized in one line:

1This is actually a special case of a more general definition: For any partition of F into two subforests, theminimum-weight edge with one endpoint in each subforest is light. A few minimum spanning tree algorithms requirethis more general definition, but we won’t talk about them here.

2The first book on graph theory, written by D. Konig, was published in 1936. Leonard Euler published his famoustheorem about the bridges of Konigsburg (HW3, problem 2) in 1736. Konigsburg was not named after that Konig.

2

Tuesday, September 24, 13

Page 58: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• El algoritmo genérico agrega repetidamente una o más aristas seguras al bosque A que evoluciona.

• Cuando agregamos nuevas aristas a A, algunas aristas indecisas se convierten en seguras, otras en inservibles.

CS 373 Lecture 13: Minimum Spanning Trees Fall 2002

and every component of F is a minimum spanning tree of its vertices. Initially, F consists of none-node trees. The generic MST algorithm merges trees together by adding certain edges betweenthem. When the algorithm halts, F consists of a single n-node tree, which must be the minimumspanning 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 isnot an edge of F , but both its endpoints are in the same component of F . For each component of F ,we associate a safe edge—the minimum-weight edge with exactly one endpoint in that component.1

Di�erent components might or might not have di�erent safe edges. Some edges are neither safe noruseless—we call these edges undecided.

All minimum spanning tree algorithms are based on two simple observations.

Lemma 1. The minimum spanning tree contains every safe edge and no useless edges.

Proof: Let T be the minimum spanning tree. Suppose F has a ‘bad’ component whose safe edgee = (u, v) is not in T . Since T is connected, it contains a unique path from u to v, and at leastone edge e� on this path has exactly one endpoint in the bad component. Removing e� from theminimum spanning tree and adding e gives us a new spanning tree. Since e is the bad component’ssafe edge, we have w(e�) > w(e), so the the new spanning tree has smaller total weight than T .But this is impossible—T is the minimum spanning tree. So T must contain every safe edge.

Adding any useless edge to F would introduce a cycle. �

u

v

e

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 tothe evolving forest F . Whenever we add new edges to F , some undecided edges become safe, andothers become useless. To specify a particular algorithm, we must decide which safe edges to add,and how to identify new safe and new useless edges, at each iteration of our generic template.

13.3 Boruvka’s Algorithm

The oldest and possibly simplest minimum spanning tree algorithm was discovered by Boruvka in1926, long before computers even existed, and practically before the invention of graph theory!2 Thealgorithm was rediscovered by Choquet in 1938; again by Florek, Lukaziewicz, Perkal, Stienhaus,and Zubrzycki in 1951; and again by Sollin some time in the early 1960s.

The Boruvka/Choquet/Florek/Lukaziewicz/Perkal/Stienhaus/Zubrzycki/Sollin algorithm canbe summarized in one line:

1This is actually a special case of a more general definition: For any partition of F into two subforests, theminimum-weight edge with one endpoint in each subforest is light. A few minimum spanning tree algorithms requirethis more general definition, but we won’t talk about them here.

2The first book on graph theory, written by D. Konig, was published in 1936. Leonard Euler published his famoustheorem about the bridges of Konigsburg (HW3, problem 2) in 1736. Konigsburg was not named after that Konig.

2

Tuesday, September 24, 13

Page 59: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• El algoritmo genérico agrega repetidamente una o más aristas seguras al bosque A que evoluciona.

• Cuando agregamos nuevas aristas a A, algunas aristas indecisas se convierten en seguras, otras en inservibles.

• Para especificar un algoritmo en particular debemos decidir qué aristas agregar y cómo identificar nuevas aristas seguras e inservibles en cada iteración del algoritmo.

CS 373 Lecture 13: Minimum Spanning Trees Fall 2002

and every component of F is a minimum spanning tree of its vertices. Initially, F consists of none-node trees. The generic MST algorithm merges trees together by adding certain edges betweenthem. When the algorithm halts, F consists of a single n-node tree, which must be the minimumspanning 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 isnot an edge of F , but both its endpoints are in the same component of F . For each component of F ,we associate a safe edge—the minimum-weight edge with exactly one endpoint in that component.1

Di�erent components might or might not have di�erent safe edges. Some edges are neither safe noruseless—we call these edges undecided.

All minimum spanning tree algorithms are based on two simple observations.

Lemma 1. The minimum spanning tree contains every safe edge and no useless edges.

Proof: Let T be the minimum spanning tree. Suppose F has a ‘bad’ component whose safe edgee = (u, v) is not in T . Since T is connected, it contains a unique path from u to v, and at leastone edge e� on this path has exactly one endpoint in the bad component. Removing e� from theminimum spanning tree and adding e gives us a new spanning tree. Since e is the bad component’ssafe edge, we have w(e�) > w(e), so the the new spanning tree has smaller total weight than T .But this is impossible—T is the minimum spanning tree. So T must contain every safe edge.

Adding any useless edge to F would introduce a cycle. �

u

v

e

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 tothe evolving forest F . Whenever we add new edges to F , some undecided edges become safe, andothers become useless. To specify a particular algorithm, we must decide which safe edges to add,and how to identify new safe and new useless edges, at each iteration of our generic template.

13.3 Boruvka’s Algorithm

The oldest and possibly simplest minimum spanning tree algorithm was discovered by Boruvka in1926, long before computers even existed, and practically before the invention of graph theory!2 Thealgorithm was rediscovered by Choquet in 1938; again by Florek, Lukaziewicz, Perkal, Stienhaus,and Zubrzycki in 1951; and again by Sollin some time in the early 1960s.

The Boruvka/Choquet/Florek/Lukaziewicz/Perkal/Stienhaus/Zubrzycki/Sollin algorithm canbe summarized in one line:

1This is actually a special case of a more general definition: For any partition of F into two subforests, theminimum-weight edge with one endpoint in each subforest is light. A few minimum spanning tree algorithms requirethis more general definition, but we won’t talk about them here.

2The first book on graph theory, written by D. Konig, was published in 1936. Leonard Euler published his famoustheorem about the bridges of Konigsburg (HW3, problem 2) in 1736. Konigsburg was not named after that Konig.

2

Tuesday, September 24, 13

Page 60: Árboles generadores mínimos (MST)

MST: algoritmo genérico

Tuesday, September 24, 13

Page 61: Árboles generadores mínimos (MST)

MST: algoritmo genérico

Generic-MST(G, w)

1 A ← ∅2 while A does not form a spanning tree3 do find and edge (u, v) that is safe for A4 A ← A ∪ {(u, v)}5 returnA

Tuesday, September 24, 13

Page 62: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Usamos la invariante al ciclo siguiente:

Generic-MST(G, w)

1 A ← ∅2 while A does not form a spanning tree3 do find and edge (u, v) that is safe for A4 A ← A ∪ {(u, v)}5 returnA

Tuesday, September 24, 13

Page 63: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Usamos la invariante al ciclo siguiente:

• Inicialización: depués de la línea 1, el conjunto A satisface la invariante trivialmente.

Generic-MST(G, w)

1 A ← ∅2 while A does not form a spanning tree3 do find and edge (u, v) that is safe for A4 A ← A ∪ {(u, v)}5 returnA

Tuesday, September 24, 13

Page 64: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Usamos la invariante al ciclo siguiente:

• Inicialización: depués de la línea 1, el conjunto A satisface la invariante trivialmente.

• Mantenimiento: el cíclo de las líneas 2 a 4 mantiene la invariante agregando solamente aristas seguras.

Generic-MST(G, w)

1 A ← ∅2 while A does not form a spanning tree3 do find and edge (u, v) that is safe for A4 A ← A ∪ {(u, v)}5 returnA

Tuesday, September 24, 13

Page 65: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Usamos la invariante al ciclo siguiente:

• Inicialización: depués de la línea 1, el conjunto A satisface la invariante trivialmente.

• Mantenimiento: el cíclo de las líneas 2 a 4 mantiene la invariante agregando solamente aristas seguras.

• Terminación: Todas las aristas que se agregan a A están en el MST y por lo tanto, al regresar A después de la línea 5, este es un MST.

Generic-MST(G, w)

1 A ← ∅2 while A does not form a spanning tree3 do find and edge (u, v) that is safe for A4 A ← A ∪ {(u, v)}5 returnA

Tuesday, September 24, 13

Page 66: Árboles generadores mínimos (MST)

MST: algoritmo genérico

Tuesday, September 24, 13

Page 67: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Problema: identificar aristas seguras (que respeten la invariante)

Tuesday, September 24, 13

Page 68: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Problema: identificar aristas seguras (que respeten la invariante)

• Un corte (cut) (S, V-S) de una gráfica no dirigida es una partición de V.

Tuesday, September 24, 13

Page 69: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Problema: identificar aristas seguras (que respeten la invariante)

• Un corte (cut) (S, V-S) de una gráfica no dirigida es una partición de V.

a

b c d

e

fg

i

h

4

8 7

9

10

1442

6

1 2

7

11

8

S ↑

V − S ↓

S ↑

V − S ↓

Tuesday, September 24, 13

Page 70: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Problema: identificar aristas seguras (que respeten la invariante)

• Un corte (cut) (S, V-S) de una gráfica no dirigida es una partición de V.

• 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.

a

b c d

e

fg

i

h

4

8 7

9

10

1442

6

1 2

7

11

8

S ↑

V − S ↓

S ↑

V − S ↓

Tuesday, September 24, 13

Page 71: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Problema: identificar aristas seguras (que respeten la invariante)

• Un corte (cut) (S, V-S) de una gráfica no dirigida es una partición de V.

• 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í?

a

b c d

e

fg

i

h

4

8 7

9

10

1442

6

1 2

7

11

8

S ↑

V − S ↓

S ↑

V − S ↓

Tuesday, September 24, 13

Page 72: Árboles generadores mínimos (MST)

MST: algoritmo genérico

Tuesday, September 24, 13

Page 73: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Decimos que un corte respeta un conjunto A de aristas si ninguna arista de A cruza el corte.

Tuesday, September 24, 13

Page 74: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Decimos que un corte respeta un conjunto A de aristas si ninguna arista de A cruza el corte.

• Una arista que cruza un corte se llama arista ligera (light edge) si su costo es el mínimo entre cualquier otra arista que cruza el corte.

Tuesday, September 24, 13

Page 75: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Decimos que un corte respeta un conjunto A de aristas si ninguna arista de A cruza el corte.

• Una arista que cruza un corte se llama arista ligera (light edge) si su costo es el mínimo entre cualquier otra arista que cruza el corte.

• Puede haber más de una arista ligera en el caso que el peso sea el mismo entre estas aristas.

Tuesday, September 24, 13

Page 76: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Decimos que un corte respeta un conjunto A de aristas si ninguna arista de A cruza el corte.

• Una arista que cruza un corte se llama arista ligera (light edge) si su costo es el mínimo entre cualquier otra arista que cruza el corte.

• Puede haber más de una arista ligera en el caso que el peso sea el mismo entre estas aristas.

• La regla para usar aristas seguras es entonces:

Tuesday, September 24, 13

Page 77: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Decimos que un corte respeta un conjunto A de aristas si ninguna arista de A cruza el corte.

• Una arista que cruza un corte se llama arista ligera (light edge) si su costo es el mínimo entre cualquier otra arista que cruza el corte.

• Puede haber más de una arista ligera en el caso que el peso sea el mismo entre estas aristas.

• La regla para usar aristas seguras es entonces:

Sea G=(V,E) una gráfica conectada, no dirigida con una función real w de costos definida 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

ligera que cruce (S,V-S). Entonces, la arista (u,v) es segura para A.

Tuesday, September 24, 13

Page 78: Árboles generadores mínimos (MST)

MST: aristas seguras

Tuesday, September 24, 13

Page 79: Árboles generadores mínimos (MST)

MST: aristas seguras

• Sea T un MST que incluye A y supongamos que T no contiene a la arista ligera (u,v).

Tuesday, September 24, 13

Page 80: Árboles generadores mínimos (MST)

MST: aristas seguras

• Sea T un MST que incluye A y supongamos que T no contiene a la arista ligera (u,v).

• Queremos construir otro MST, T’ que incluya A ∪ {(u,v)} mostrando que (u,v) es una arista segura.

Tuesday, September 24, 13

Page 81: Árboles generadores mínimos (MST)

MST: aristas seguras

• Sea T un MST que incluye A y supongamos que T no contiene a la arista ligera (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 cíclo con las aristas del camino p desde u hasta v en T.

Tuesday, September 24, 13

Page 82: Árboles generadores mínimos (MST)

MST: aristas seguras

• Sea T un MST que incluye A y supongamos que T no contiene a la arista ligera (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 cíclo con las aristas del camino p desde u hasta v en T.

• Ya que u y v están en lados opuestos del corte (S,V-S), hay al menos una arista en T en el camino p que también cruza el corte.

Tuesday, September 24, 13

Page 83: Árboles generadores mínimos (MST)

MST: aristas seguras

• Sea T un MST que incluye A y supongamos que T no contiene a la arista ligera (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 cíclo con las aristas del camino p desde u hasta v en T.

• Ya que u y v están en lados opuestos del corte (S,V-S), hay al menos una arista en T en el camino p que también cruza el corte.

• (x,y) no está en A porque sabemos que el corte respeta A.

Tuesday, September 24, 13

Page 84: Árboles generadores mínimos (MST)

MST: aristas seguras

• Sea T un MST que incluye A y supongamos que T no contiene a la arista ligera (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 cíclo con las aristas del camino p desde u hasta v en T.

• Ya que u y v están en lados opuestos del corte (S,V-S), hay al menos una arista en T en el camino p que también cruza el corte.

• (x,y) no está en A porque sabemos que el corte respeta A.

u

p

T

A

y

v

x

V-S

S

(u,v)

(x,y)

Tuesday, September 24, 13

Page 85: Árboles generadores mínimos (MST)

MST: aristas seguras

Tuesday, September 24, 13

Page 86: Árboles generadores mínimos (MST)

MST: aristas seguras

• Ya que (x,y) está en el único camino p desde u hasta v en T, remover (x,y) desconecta T en dos componentes.

Tuesday, September 24, 13

Page 87: Árboles generadores mínimos (MST)

MST: aristas seguras

• 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:

Tuesday, September 24, 13

Page 88: Árboles generadores mínimos (MST)

MST: aristas seguras

• 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)}.

Tuesday, September 24, 13

Page 89: Árboles generadores mínimos (MST)

MST: aristas seguras

• 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)}.

u

p

T

A

y

v

x

V-S

S

(u,v)

(x,y)

Tuesday, September 24, 13

Page 90: Árboles generadores mínimos (MST)

MST: aristas seguras

Tuesday, September 24, 13

Page 91: Árboles generadores mínimos (MST)

• Probamos que T’ es un MST:

MST: aristas seguras

Tuesday, September 24, 13

Page 92: Árboles generadores mínimos (MST)

• Probamos que T’ es un MST:

• Ya que (u,v) es una arista ligera que cruza (S, V-S) y (x,y) también cruza el corte, w(u,v) ≤ w(x,y).

MST: aristas seguras

Tuesday, September 24, 13

Page 93: Árboles generadores mínimos (MST)

• Probamos que T’ es un MST:

• Ya que (u,v) es una arista ligera que cruza (S, V-S) y (x,y) también cruza el corte, w(u,v) ≤ w(x,y).

• Entonces:

MST: aristas seguras

Tuesday, September 24, 13

Page 94: Árboles generadores mínimos (MST)

• Probamos que T’ es un MST:

• Ya que (u,v) es una arista ligera que cruza (S, V-S) y (x,y) también cruza el corte, w(u,v) ≤ w(x,y).

• Entonces:

w(T’) = w(T) - w(x,y) + w(u,v)

MST: aristas seguras

Tuesday, September 24, 13

Page 95: Árboles generadores mínimos (MST)

• Probamos que T’ es un MST:

• Ya que (u,v) es una arista ligera que cruza (S, V-S) y (x,y) también cruza el corte, w(u,v) ≤ w(x,y).

• Entonces:

w(T’) = w(T) - w(x,y) + w(u,v)

≤ w(T)

MST: aristas seguras

Tuesday, September 24, 13

Page 96: Árboles generadores mínimos (MST)

• Probamos que T’ es un MST:

• Ya que (u,v) es una arista ligera que cruza (S, V-S) y (x,y) también cruza el corte, w(u,v) ≤ w(x,y).

• Entonces:

w(T’) = w(T) - w(x,y) + w(u,v)

≤ w(T)

• Como T es un MST, w(T’) ≤ w(T), entonces T’ debe ser también un MST.

MST: aristas seguras

Tuesday, September 24, 13

Page 97: Árboles generadores mínimos (MST)

• Probamos que T’ es un MST:

• Ya que (u,v) es una arista ligera que cruza (S, V-S) y (x,y) también cruza el corte, w(u,v) ≤ w(x,y).

• Entonces:

w(T’) = w(T) - w(x,y) + w(u,v)

≤ w(T)

• Como T es un MST, w(T’) ≤ w(T), entonces T’ debe ser también un MST.

• Ya que T’ es un MST, (u,v) es una arista segura para A.

MST: aristas seguras

Tuesday, September 24, 13

Page 98: Árboles generadores mínimos (MST)

MST: algoritmo genérico

Tuesday, September 24, 13

Page 99: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Mientras el algoritmo avanza, el conjunto A es siempre acíclico, de otra forma el MST que incluye A contendría un cíclo, lo que es contradictorio.

Tuesday, September 24, 13

Page 100: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Mientras el algoritmo avanza, el conjunto A es siempre acíclico, de otra forma el MST que incluye A contendría un cíclo, lo que es contradictorio.

• En cualquier momento de la ejecución del algoritmo, la gráfica GA = (V,A) es un bosque, en donde cada componente de GA es un árbol.

Tuesday, September 24, 13

Page 101: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Mientras el algoritmo avanza, el conjunto A es siempre acíclico, de otra forma el MST que incluye A contendría un cíclo, lo que es contradictorio.

• En cualquier momento de la ejecución del algoritmo, la gráfica GA = (V,A) es un bosque, en donde cada componente de GA es un árbol.

• Algunos de estos árboles pueden contener un solo vértice (al inicio del algoritmo por ejemplo).

Tuesday, September 24, 13

Page 102: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Mientras el algoritmo avanza, el conjunto A es siempre acíclico, de otra forma el MST que incluye A contendría un cíclo, lo que es contradictorio.

• En cualquier momento de la ejecución del algoritmo, la gráfica GA = (V,A) es un bosque, en donde cada componente de GA es un árbol.

• Algunos de estos árboles pueden contener un solo vértice (al inicio del algoritmo por ejemplo).

• Cualquier arista segura conecta dos componentes de GA.

Tuesday, September 24, 13

Page 103: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Mientras el algoritmo avanza, el conjunto A es siempre acíclico, de otra forma el MST que incluye A contendría un cíclo, lo que es contradictorio.

• En cualquier momento de la ejecución del algoritmo, la gráfica GA = (V,A) es un bosque, en donde cada componente de GA es un árbol.

• Algunos de estos árboles pueden contener un solo vértice (al inicio del algoritmo por ejemplo).

• Cualquier arista segura conecta dos componentes de GA.

• El cíclo de las líneas 2 a 4 de GENERIC-MST se ejecuta, ¿cuántas veces?

Tuesday, September 24, 13

Page 104: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Mientras el algoritmo avanza, el conjunto A es siempre acíclico, de otra forma el MST que incluye A contendría un cíclo, lo que es contradictorio.

• En cualquier momento de la ejecución del algoritmo, la gráfica GA = (V,A) es un bosque, en donde cada componente de GA es un árbol.

• Algunos de estos árboles pueden contener un solo vértice (al inicio del algoritmo por ejemplo).

• Cualquier arista segura conecta dos componentes de GA.

• El cíclo de las líneas 2 a 4 de GENERIC-MST se ejecuta, ¿cuántas veces?

• V-1 veces.

Tuesday, September 24, 13

Page 105: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Mientras el algoritmo avanza, el conjunto A es siempre acíclico, de otra forma el MST que incluye A contendría un cíclo, lo que es contradictorio.

• En cualquier momento de la ejecución del algoritmo, la gráfica GA = (V,A) es un bosque, en donde cada componente de GA es un árbol.

• Algunos de estos árboles pueden contener un solo vértice (al inicio del algoritmo por ejemplo).

• Cualquier arista segura conecta dos componentes de GA.

• El cíclo de las líneas 2 a 4 de GENERIC-MST se ejecuta, ¿cuántas veces?

• V-1 veces.

• ¿Cuándo termina el algoritmo?

Tuesday, September 24, 13

Page 106: Árboles generadores mínimos (MST)

MST: algoritmo genérico

• Mientras el algoritmo avanza, el conjunto A es siempre acíclico, de otra forma el MST que incluye A contendría un cíclo, lo que es contradictorio.

• En cualquier momento de la ejecución del algoritmo, la gráfica GA = (V,A) es un bosque, en donde cada componente de GA es un árbol.

• Algunos de estos árboles pueden contener un solo vértice (al inicio del algoritmo por ejemplo).

• Cualquier arista segura conecta dos componentes de GA.

• El cíclo de las líneas 2 a 4 de GENERIC-MST se ejecuta, ¿cuántas veces?

• V-1 veces.

• ¿Cuándo termina el algoritmo?

• cuando el bosque contiene sólo un árbol.

Tuesday, September 24, 13

Page 107: Árboles generadores mínimos (MST)

Corolario

Tuesday, September 24, 13

Page 108: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka

Tuesday, September 24, 13

Page 109: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Ideado por Otakar Borůvka (1899-1995)

Tuesday, September 24, 13

Page 110: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Ideado por Otakar Borůvka (1899-1995)

Tuesday, September 24, 13

Page 111: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Ideado por Otakar Borůvka (1899-1995)

• En su artículo “On a certain minimal problem” describió un algoritmo para encontrar el MST de una red eléctrica (1926).

Tuesday, September 24, 13

Page 112: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Ideado por Otakar Borůvka (1899-1995)

• En su artículo “On a certain minimal problem” describió un algoritmo para encontrar el MST de una red eléctrica (1926).

• ¿Qué buscaría Borůvka en esta aplicación?

Tuesday, September 24, 13

Page 113: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Ideado por Otakar Borůvka (1899-1995)

• En su artículo “On a certain minimal problem” describió un algoritmo para encontrar el MST de una red eléctrica (1926).

• ¿Qué buscaría Borůvka en esta aplicación?

• encontrar la construcción más económica de la red eléctrica.

Tuesday, September 24, 13

Page 114: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Ideado por Otakar Borůvka (1899-1995)

• En su artículo “On a certain minimal problem” describió un algoritmo para encontrar el MST de una red eléctrica (1926).

• ¿Qué buscaría Borůvka en esta aplicación?

• encontrar la construcción más económica de la red eléctrica.

• Problema concreto de ingeniería que se convirtió en un modelo de problema para la optimización combinatoria.

Tuesday, September 24, 13

Page 115: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Ideado por Otakar Borůvka (1899-1995)

• En su artículo “On a certain minimal problem” describió un algoritmo para encontrar el MST de una red eléctrica (1926).

• ¿Qué buscaría Borůvka en esta aplicación?

• encontrar la construcción más económica de la red eléctrica.

• Problema concreto de ingeniería que se convirtió en un modelo de problema para la optimización combinatoria.

• Es el algoritmo más antiguo y posiblemente el más simple para encontrar MST.

Tuesday, September 24, 13

Page 116: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Ideado por Otakar Borůvka (1899-1995)

• En su artículo “On a certain minimal problem” describió un algoritmo para encontrar el MST de una red eléctrica (1926).

• ¿Qué buscaría Borůvka en esta aplicación?

• encontrar la construcción más económica de la red eléctrica.

• Problema concreto de ingeniería que se convirtió en un modelo de problema para la optimización combinatoria.

• Es el algoritmo más antiguo y posiblemente el más simple para encontrar MST.

• Redescubierto por Choquet, Florek, Lukaziewicz, Perkal, Steinhaus, Zubrzycki y Sollin.

Tuesday, September 24, 13

Page 117: Árboles generadores mínimos (MST)

MST: Algoritmo de BorůvkaCS 373 Lecture 13: Minimum Spanning Trees Fall 2002

Boruvka: Add all the safe edges and recurse.

8 5

10

2 3

18 16

12

14

30

4 26

18

12

14

26

Boruvka’s algorithm run on the example graph. Thick edges are in F .Arrows point along each component’s safe edge. Dashed edges are useless.

At the beginning of each phase of the Boruvka algorithm, each component elects an arbitrary‘leader’ node. The simplest way to hold these elections is a depth-first search of F ; the first nodewe visit in any component is that component’s leader. Once the leaders are elected, we find thesafe edges for each component, essentially by brute force. Finally, we add these safe edges to F .

Boruvka(V,E):F = (V, �)while F has more than one component

choose leaders using DFSFindSafeEdges(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 graph isconnected, it has at most E + 1 vertices. Thus, each iteration of the while loop in Boruvka takesO(E) time, assuming the graph is represented by an adjacency list. Each iteration also reduces thenumber of components of F by at least a factor of two—the worst case occurs when the componentscoalesce in pairs. Since there are initially V components, the while loop iterates O(log V ) times.Thus, the overall running time of Boruvka’s algorithm is O(E log V ) .

Despite its relatively obscure origin, early algorithms researchers were aware of Boruvka’s algo-rithm, but dismissed it as being “too complicated”! As a result, despite its simplicity and e⇤ciency,Boruvka’s algorithm is rarely mentioned in algorithms and data structures textbooks.

13.4 Jarnık’s (‘Prim’s’) Algorithm

The next oldest minimum spanning tree algorithm was discovered by the Vojtech Jarnık in 1930,but it is usually called Prim’s algorithm. Prim independently rediscovered the algorithm in 1956and gave a much more detailed description than Jarnık. The algorithm was rediscovered again in1958 by Dijkstra, but he already had an algorithm named after him. Such is fame in academia.

In Jarnık’s algorithm, the forest F contains only one nontrivial component T ; all the othercomponents are isolated vertices. Initially, T consists of an arbitrary vertex of the graph. Thealgorithm repeats the following step until T spans the whole graph:

3

Tuesday, September 24, 13

Page 118: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka

• Encontramos las aristas seguras para cada componente, por fuerza bruta y estas son agregadas a T.

CS 373 Lecture 13: Minimum Spanning Trees Fall 2002

Boruvka: Add all the safe edges and recurse.

8 5

10

2 3

18 16

12

14

30

4 26

18

12

14

26

Boruvka’s algorithm run on the example graph. Thick edges are in F .Arrows point along each component’s safe edge. Dashed edges are useless.

At the beginning of each phase of the Boruvka algorithm, each component elects an arbitrary‘leader’ node. The simplest way to hold these elections is a depth-first search of F ; the first nodewe visit in any component is that component’s leader. Once the leaders are elected, we find thesafe edges for each component, essentially by brute force. Finally, we add these safe edges to F .

Boruvka(V,E):F = (V, �)while F has more than one component

choose leaders using DFSFindSafeEdges(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 graph isconnected, it has at most E + 1 vertices. Thus, each iteration of the while loop in Boruvka takesO(E) time, assuming the graph is represented by an adjacency list. Each iteration also reduces thenumber of components of F by at least a factor of two—the worst case occurs when the componentscoalesce in pairs. Since there are initially V components, the while loop iterates O(log V ) times.Thus, the overall running time of Boruvka’s algorithm is O(E log V ) .

Despite its relatively obscure origin, early algorithms researchers were aware of Boruvka’s algo-rithm, but dismissed it as being “too complicated”! As a result, despite its simplicity and e⇤ciency,Boruvka’s algorithm is rarely mentioned in algorithms and data structures textbooks.

13.4 Jarnık’s (‘Prim’s’) Algorithm

The next oldest minimum spanning tree algorithm was discovered by the Vojtech Jarnık in 1930,but it is usually called Prim’s algorithm. Prim independently rediscovered the algorithm in 1956and gave a much more detailed description than Jarnık. The algorithm was rediscovered again in1958 by Dijkstra, but he already had an algorithm named after him. Such is fame in academia.

In Jarnık’s algorithm, the forest F contains only one nontrivial component T ; all the othercomponents are isolated vertices. Initially, T consists of an arbitrary vertex of the graph. Thealgorithm repeats the following step until T spans the whole graph:

3

Tuesday, September 24, 13

Page 119: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka

• Encontramos las aristas seguras para cada componente, por fuerza bruta y estas son agregadas a T.

CS 373 Lecture 13: Minimum Spanning Trees Fall 2002

Boruvka: Add all the safe edges and recurse.

8 5

10

2 3

18 16

12

14

30

4 26

18

12

14

26

Boruvka’s algorithm run on the example graph. Thick edges are in F .Arrows point along each component’s safe edge. Dashed edges are useless.

At the beginning of each phase of the Boruvka algorithm, each component elects an arbitrary‘leader’ node. The simplest way to hold these elections is a depth-first search of F ; the first nodewe visit in any component is that component’s leader. Once the leaders are elected, we find thesafe edges for each component, essentially by brute force. Finally, we add these safe edges to F .

Boruvka(V,E):F = (V, �)while F has more than one component

choose leaders using DFSFindSafeEdges(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 graph isconnected, it has at most E + 1 vertices. Thus, each iteration of the while loop in Boruvka takesO(E) time, assuming the graph is represented by an adjacency list. Each iteration also reduces thenumber of components of F by at least a factor of two—the worst case occurs when the componentscoalesce in pairs. Since there are initially V components, the while loop iterates O(log V ) times.Thus, the overall running time of Boruvka’s algorithm is O(E log V ) .

Despite its relatively obscure origin, early algorithms researchers were aware of Boruvka’s algo-rithm, but dismissed it as being “too complicated”! As a result, despite its simplicity and e⇤ciency,Boruvka’s algorithm is rarely mentioned in algorithms and data structures textbooks.

13.4 Jarnık’s (‘Prim’s’) Algorithm

The next oldest minimum spanning tree algorithm was discovered by the Vojtech Jarnık in 1930,but it is usually called Prim’s algorithm. Prim independently rediscovered the algorithm in 1956and gave a much more detailed description than Jarnık. The algorithm was rediscovered again in1958 by Dijkstra, but he already had an algorithm named after him. Such is fame in academia.

In Jarnık’s algorithm, the forest F contains only one nontrivial component T ; all the othercomponents are isolated vertices. Initially, T consists of an arbitrary vertex of the graph. Thealgorithm repeats the following step until T spans the whole graph:

3

CS 373 Lecture 13: Minimum Spanning Trees Fall 2002

Boruvka: Add all the safe edges and recurse.

8 5

10

2 3

18 16

12

14

30

4 26

18

12

14

26

Boruvka’s algorithm run on the example graph. Thick edges are in F .Arrows point along each component’s safe edge. Dashed edges are useless.

At the beginning of each phase of the Boruvka algorithm, each component elects an arbitrary‘leader’ node. The simplest way to hold these elections is a depth-first search of F ; the first nodewe visit in any component is that component’s leader. Once the leaders are elected, we find thesafe edges for each component, essentially by brute force. Finally, we add these safe edges to F .

Boruvka(V,E):F = (V, �)while F has more than one component

choose leaders using DFSFindSafeEdges(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 graph isconnected, it has at most E + 1 vertices. Thus, each iteration of the while loop in Boruvka takesO(E) time, assuming the graph is represented by an adjacency list. Each iteration also reduces thenumber of components of F by at least a factor of two—the worst case occurs when the componentscoalesce in pairs. Since there are initially V components, the while loop iterates O(log V ) times.Thus, the overall running time of Boruvka’s algorithm is O(E log V ) .

Despite its relatively obscure origin, early algorithms researchers were aware of Boruvka’s algo-rithm, but dismissed it as being “too complicated”! As a result, despite its simplicity and e⇤ciency,Boruvka’s algorithm is rarely mentioned in algorithms and data structures textbooks.

13.4 Jarnık’s (‘Prim’s’) Algorithm

The next oldest minimum spanning tree algorithm was discovered by the Vojtech Jarnık in 1930,but it is usually called Prim’s algorithm. Prim independently rediscovered the algorithm in 1956and gave a much more detailed description than Jarnık. The algorithm was rediscovered again in1958 by Dijkstra, but he already had an algorithm named after him. Such is fame in academia.

In Jarnık’s algorithm, the forest F contains only one nontrivial component T ; all the othercomponents are isolated vertices. Initially, T consists of an arbitrary vertex of the graph. Thealgorithm repeats the following step until T spans the whole graph:

3

Tuesday, September 24, 13

Page 120: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka

Tuesday, September 24, 13

Page 121: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka

CS 373 Lecture 13: Minimum Spanning Trees Fall 2002

Boruvka: Add all the safe edges and recurse.

8 5

10

2 3

18 16

12

14

30

4 26

18

12

14

26

Boruvka’s algorithm run on the example graph. Thick edges are in F .Arrows point along each component’s safe edge. Dashed edges are useless.

At the beginning of each phase of the Boruvka algorithm, each component elects an arbitrary‘leader’ node. The simplest way to hold these elections is a depth-first search of F ; the first nodewe visit in any component is that component’s leader. Once the leaders are elected, we find thesafe edges for each component, essentially by brute force. Finally, we add these safe edges to F .

Boruvka(V,E):F = (V, �)while F has more than one component

choose leaders using DFSFindSafeEdges(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 graph isconnected, it has at most E + 1 vertices. Thus, each iteration of the while loop in Boruvka takesO(E) time, assuming the graph is represented by an adjacency list. Each iteration also reduces thenumber of components of F by at least a factor of two—the worst case occurs when the componentscoalesce in pairs. Since there are initially V components, the while loop iterates O(log V ) times.Thus, the overall running time of Boruvka’s algorithm is O(E log V ) .

Despite its relatively obscure origin, early algorithms researchers were aware of Boruvka’s algo-rithm, but dismissed it as being “too complicated”! As a result, despite its simplicity and e⇤ciency,Boruvka’s algorithm is rarely mentioned in algorithms and data structures textbooks.

13.4 Jarnık’s (‘Prim’s’) Algorithm

The next oldest minimum spanning tree algorithm was discovered by the Vojtech Jarnık in 1930,but it is usually called Prim’s algorithm. Prim independently rediscovered the algorithm in 1956and gave a much more detailed description than Jarnık. The algorithm was rediscovered again in1958 by Dijkstra, but he already had an algorithm named after him. Such is fame in academia.

In Jarnık’s algorithm, the forest F contains only one nontrivial component T ; all the othercomponents are isolated vertices. Initially, T consists of an arbitrary vertex of the graph. Thealgorithm repeats the following step until T spans the whole graph:

3

Tuesday, September 24, 13

Page 122: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka

Tuesday, September 24, 13

Page 123: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Cada llamada a Find the cheapest edge (FindSafeEdges) toma ...

Tuesday, September 24, 13

Page 124: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Cada llamada a Find the cheapest edge (FindSafeEdges) toma ...

• O(E) porque examina cada arista.

Tuesday, September 24, 13

Page 125: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Cada llamada a Find the cheapest edge (FindSafeEdges) toma ...

• O(E) porque examina cada arista.

• Como la gráfica es conectada, ¿cuántos vértices tiene a lo más?

Tuesday, September 24, 13

Page 126: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Cada llamada a Find the cheapest edge (FindSafeEdges) toma ...

• O(E) porque examina cada arista.

• Como la gráfica es conectada, ¿cuántos vértices tiene a lo más?

• E+1 vértices.

Tuesday, September 24, 13

Page 127: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Cada llamada a Find the cheapest edge (FindSafeEdges) toma ...

• O(E) porque examina cada arista.

• Como la gráfica es conectada, ¿cuántos vértices tiene a lo más?

• E+1 vértices.

• Cada iteración del ciclo while en Boruvka toma ... (suponiendo una representación por listas de adyacencia)

Tuesday, September 24, 13

Page 128: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Cada llamada a Find the cheapest edge (FindSafeEdges) toma ...

• O(E) porque examina cada arista.

• Como la gráfica es conectada, ¿cuántos vértices tiene a lo más?

• E+1 vértices.

• Cada iteración del ciclo while en Boruvka toma ... (suponiendo una representación por listas de adyacencia)

• O(E).

Tuesday, September 24, 13

Page 129: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Cada llamada a Find the cheapest edge (FindSafeEdges) toma ...

• O(E) porque examina cada arista.

• Como la gráfica es conectada, ¿cuántos vértices tiene a lo más?

• E+1 vértices.

• Cada iteración del ciclo while en Boruvka toma ... (suponiendo una representación por listas de adyacencia)

• O(E).

• Cada iteración reduce el número de componentes de A al menos en un factor de dos.

Tuesday, September 24, 13

Page 130: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Cada llamada a Find the cheapest edge (FindSafeEdges) toma ...

• O(E) porque examina cada arista.

• Como la gráfica es conectada, ¿cuántos vértices tiene a lo más?

• E+1 vértices.

• Cada iteración del ciclo while en Boruvka toma ... (suponiendo una representación por listas de adyacencia)

• O(E).

• Cada iteración reduce el número de componentes de A al menos en un factor de dos.

• Como al inicio hay V componentes, el cíclo while itera...¿cuántas veces?

Tuesday, September 24, 13

Page 131: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Cada llamada a Find the cheapest edge (FindSafeEdges) toma ...

• O(E) porque examina cada arista.

• Como la gráfica es conectada, ¿cuántos vértices tiene a lo más?

• E+1 vértices.

• Cada iteración del ciclo while en Boruvka toma ... (suponiendo una representación por listas de adyacencia)

• O(E).

• Cada iteración reduce el número de componentes de A al menos en un factor de dos.

• Como al inicio hay V componentes, el cíclo while itera...¿cuántas veces?

• O(log V) veces.

Tuesday, September 24, 13

Page 132: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Cada llamada a Find the cheapest edge (FindSafeEdges) toma ...

• O(E) porque examina cada arista.

• Como la gráfica es conectada, ¿cuántos vértices tiene a lo más?

• E+1 vértices.

• Cada iteración del ciclo while en Boruvka toma ... (suponiendo una representación por listas de adyacencia)

• O(E).

• Cada iteración reduce el número de componentes de A al menos en un factor de dos.

• Como al inicio hay V componentes, el cíclo while itera...¿cuántas veces?

• O(log V) veces.

• El tiempo total de ejecución es entonces ...

Tuesday, September 24, 13

Page 133: Árboles generadores mínimos (MST)

MST: Algoritmo de Borůvka• Cada llamada a Find the cheapest edge (FindSafeEdges) toma ...

• O(E) porque examina cada arista.

• Como la gráfica es conectada, ¿cuántos vértices tiene a lo más?

• E+1 vértices.

• Cada iteración del ciclo while en Boruvka toma ... (suponiendo una representación por listas de adyacencia)

• O(E).

• Cada iteración reduce el número de componentes de A al menos en un factor de dos.

• Como al inicio hay V componentes, el cíclo while itera...¿cuántas veces?

• O(log V) veces.

• El tiempo total de ejecución es entonces ...

• O(E log V).

Tuesday, September 24, 13


Recommended