Minimum span

zhaozj2021-02-12  125

The formation of minimally genes

Suppose is known to have a non-portrait chart G = (V, E), whose weighting function is W: E → R, we want to find the smallest span tree of Figure G. The two algorithms discussed later have used greed, but they have different ways to use greed.

The following algorithms genernic-mit are using a greedy strategy, and each step is formed to form a side of the minimum tree. The algorithm sets a collection A that has always been a subset of a minimally generated tree. In each step, it is determined whether to add edge (u, v) to the set A, which is added to the A ∪ {(u, v)} is still a subset of the minimally generated tree. We call this side of the safety side of A because it can be safely added to A without damaging the above conditions.

Genernic-mit (g, w)

1. a ←?

2. While A does not form a spanning tree

3 do find a safety side (U, V);

4. a ← A∪ {(U, V)};

5. Return A

Note After the first line, A obviously meets the conditions of the minimum generated tree set. This condition is maintained in the cycle of the second line, and when returns a collection a in the 5th line, a is inevitably a minimum tree. The most tricky part of the algorithm is naturally the second line of search safety side. There must be a bunch of a tree, because when the third line of code is executed, there is a tree T in accordance with the conditional requirements, so that Aít, and if there is edge (U, V)? T, (u, v)? A, then (U , V) is the safety side of A.

In this section of this festival, we will propose a rule (theorem 1) that confirm the safety side (theorem 1), the next section we will use this rule to find two valid algorithms for safety side.

First let's define a few concepts. The cut (S, V-S) of the view g = (v, e) is a diverting of V. When one end of one (U, V)? E belongs to S and the other end point belongs to V-S, we say that edge (u, v) is cut (S, V-S). If there is no side by cutting in the collection A, we say that we will cut the collection A. If a sidelines have the sides having the minimum weight, it is called the sides of a light side. Be careful to have multiple light edges in the case of the link. From a more general sense, if a side is the side with minimal weight in all edges that satisfy a certain nature, we call this side to satisfy a light side of this nature. Figure 2 illustrates these concepts. (a) The nodes in the collection S are black nodes, and those in V-S are white nodes. Those sides connected to the white and black nodes are through the cut edge. Side (d, c) is the only light side by this cut. The subset A contains the edges covering the shadow, note that the cut (S, V-S) does not disappear because there is no side in A. (b) For the same map, we put the nodes in the collection S on the left side of the figure, and the nodes in the set V-S are placed on the figure. If a side is connected to the vertices on the left, we say that the edge is cut.

(a)

(b)

Figure 2 observes the cut (S, V-S) shown in Fig. 1 from two ways.

Verify that the rules of the safety side are given by the following theorem.

Theorem 1

The graph G (V, E) is a non-converging map, and the corresponding real value weighting function W is defined on E, and a subset of A is E is a subset of E and includes a minimum tree of G, cutting (S, vs) is a mulled mulled A of G and the side (U, V) is a light side passing through the cut (S, Vs), and the edge (U, V) is safe.

prove:

Set T is a minimum tree containing A and assumes that T does not include light edges (U, V), because if the included is included, it is proof. We will use the "cut-paSte technique" to establish another minimum tree T ¢ containing a ∪ {(u, v)}, and further prove (U, V) to A is a safety side. ;

Figure 3 Proof of theorem 1

Figure 3 shows the proof of theorem 1. The junction in S is black, and the nodes in V-S are white, and the edges (U, V) are constituted from the edges of the path P from U to V in T. Since U and V are in the opposite edges of cut (S, V-S), at least one side is at least one side in the passage p in T. Setting (x, y) to satisfy the edges of this condition. Because the cut does not hurt A, the side (x, y) is not A. Also because (x, y) is in the unique passage from U to V, then remove the T, the T is divided into two subgraphs. At this time, edge (U, V) is added to form a new spanning tree T ¢ = T - {(x, y)} ∪ {(u, v)}. Next, we prove that T ¢ is a minimum tree. Since the edge (u, V) is a light side by cutting (S, VS) and the edges (x, y) are passed, W (u, v) £ W (X, Y), so W (T ¢) = w (t) -w (x, y) w (u, v) £ (t), but T is the minimum spanning tree, so W (t) = w (t ¢), so T ¢ must also Minimum spanning tree.

It is now necessary to demonstrate (u, v) is actually a safe side of A. Because of Aít and (x, y)? A, there is a ít ¢, then a ∪ {(u, v)} ít ¢. And t ¢ is the minimum spanning tree, so (u, v) is secure. □

Theorem 1 allows us to better understand the execution process of the genernic-mit on the connecting map G = (V, E). During the execution of the algorithm, the collection A is always free, otherwise the smallest span tree containing A contains a ring, which is impossible. At any time in the algorithm execution, GA = (v, a) is a forest and each of GA is a tree. Some trees may contain only one node, such as at the beginning of the algorithm, A is empty set, including | V | tree, each vertex corresponds to one. In addition, any edges (u, v) of a secure side (U, V) are connected to different communication branches in GA, which is because the A∪ {(U, V)} must not contain loops.

As the minimum spanned tree | V | -1 is determined, the cycle of the second-4 line in GENERNIC-MIT also performs | V | -1. In the initial state, A = ?, ga has | V | tree, each iterative process will reduce a tree, when only one tree is included in the forest, the algorithm performs termination.

The two algorithms discussed in Section 2 use the inference of the following theorem 1.

Inference 2

Setting G = (v, e) is an undirected communication map, and the corresponding real value weighting function W is defined in E, and a subset of E is E is a subset of E and includes a minimum tree tree containing G, c is the forest. The communication branch (tree) in Ga = (V, a). If both (U, V) is a light side that connects C and other conjunction in other consecutive branches, the edges (u, v) are safe to set A.

prove:

Because cut (C, V-C) does not dismiss A, (U, V) is a light side of the cut. □

5.1 Basic Concept of Figure

5.2 storage structure

5.3 traversal

5.4 Spanning Tree and Minimum Generate Tree

5.5 shortest path problem

5.6 Topology Sort

         

             

From the point of view, the tree is also a picture, but it is a non-portable chart. We can also call the tree as a tree map.

Traverse the non-portable communication map, simply call the traversal algorithm to obtain the access sequences of the various vertices of the map, this access sequence (path) is a spanning tree of the communication map. Obviously, a spanning tree that is unreported may not be unique. We generally prioritize the depth priority search for deep priority to become trees, and the breadth priority search has been widely played for the breadth priority. Figure 5.9 can be obtained in depth and priority and by width, which is prioritized to obtain two generation trees as shown in Figure 5.10.

 

            

5.4.2 Minimal Generation Tree                            

A illegally network, in all spanning trees of the map, make the minimum spanning trees of each side, and the minimum tree of the map, also called the minimum cost to generate a tree.

★ Let's first look at an example

Take the construction of the road network, what kind of map can connect all the towns and minimize the length? It is not difficult to see that the answer can only be found from its spanning trees, because there is a highway between any two towns, the road network must be connected, but the requirements for the length can know the road network Obviously, there is no loop. If there is a circle, after the edge on the map, it does not destroy the connectivity, but the total length is obviously reduced, which is contradictory with the smallest intelligence with the total length.

★ The practical significance of this example is obvious. Under the conditions of all towns, the number of construction kilters minimizes, thereby reducing costs.

[Improve] Algorithm for minimally generating trees (increase)

Constructing Minimum Spanning Tree algorithm many, most of the algorithm is the use of the minimum spanning tree of the following properties:  set G = (V, E) is a weighted FIG communication, U is a non-air set of vertices set V. If u belongs to u, V belongs to VU, and (u, v) is the minimum weight between the U.States to the top of the VU, it must be present (u) The minimum span tree of V).

     

            

5.4.3: Solving the minimum span of the drawing

(                                                                        

1. Kruskal algorithm

The basic idea of ​​the Kruskal algorithm is:

★ (1) If the number of edges of the network G is E = N-1, the G is the minimum spanning tree asked, otherwise, E> N-1 must be present.

★ (2) Align the E-strip of the network from the weight of the value to the large order.

★ (3) Remove the edges of the network G, leaving only N isolated vertices as the initial minimum spanning tree T, and then press the sequence of the emission order, if the edge is not constituted in the current e (t) , Add it to the sideset E (T) until the number of full (n-1) in the E (T).

[Important]

Kruskal algorithm gives a method of constructing a minimum (price) span tree by selecting a sub-order of the weight.

For example, the smallest span tree obtained by the network shown in Kruskal method is shown in Figure 5.12.

Like a spanning tree, the minimum spanning tree may not be unique.

 

2. PRIM algorithm

The PRIM algorithm is another method for the smallest spanning tree. Its basic idea is to add the vertices and sides into T by the minimum level of the weight, until V (t) is full of N top points.

The step of the PRIM algorithm is:

(1) It is empty to set the minimum spanning tree t.                                                                     .                                                                                         VJ) where the VI is included in V (t),   VJ contains V (t).                                                 In, the vertex VJ is incorporated into V (t).                                                                                            In the program of implementing the Prim algorithm, we use the adjacent matrix to express a given band-right communication (as follows), &: indicate infinity

0

1

2

3

4

5

0

0

3

9

&

15

&

1

3

0

1

9

&

Seduce

2

9

1

0

5

2

&

3

&

9

5

0

11

4

4

15

&

2

11

0

13

5

&

Seduce

&

4

13

0

[Important]

In order to implement this algorithm, an array close can be introduced to reflect the status of the currently selected top point, and the initial all of the array element is 1. An array close-de-reflecting the status of the selected border, if close [i] = 0, the vertex I has been selected to the vertices, the corresponding edge is (I, Closedge).

>> Continue <<  >> Back <<