Analysis of secondary short-circuit and sub-niche tree-forming algorithm

Source: Internet
Author: User
analysis of secondary short-circuit and sub-niche tree-forming algorithm

This article is not original, tribute to the original, address: https://blog.csdn.net/u010016150/article/details/12992571 [secondary short path]

The second shortest path can be regarded as a special case of K-short path problem, and it is more complicated to find the yen algorithm for K-short path, and it can have a more simple method for the short-time path. The following is a solution for finding a short path between two vertices.

We want to find a short path between the vertices s to t of a weighted graph (an anisotropic graph with each edge as two opposite), and first we should find the single-source shortest path of S. Traverse the graph to mark the edges that can be on the shortest path and join the set K. The enumeration then deletes each edge in the set K, seeking the shortest path from S to T, and records the path length value each time it is calculated, and the minimum value is the length of the second short path.

Here we think that the second short path length can be equal to the shortest path length, if you want to wait, can also be seen from S to t have more than one shortest path. If we specify a short path from S to t greater than the shortest path length, the answer is the minimum of the shortest path length of s to t that is greater than the original shortest path after each deletion.

To find the shortest path of single source with dijkstra+ heap, the shortest path time complexity is O (Nlog (n+m) +m) O (n l o g (n + m) + M) O (Nlog (n+m) +m), so the total time complexity is O (Nm∗log (n+m) +m2) o (N m∗l o g (n + m) + M 2) O (Nm*log (n+m) + m^2). This estimate is more pessimistic, because in general, the number of edges on the shortest path is much smaller than m, so the actual effect is better than expected. [sub-niche into a tree]

Analogy to the above-mentioned short path method, it is easy to think of an "enumeration to delete the minimum spanning tree on each edge, and then the minimum spanning tree" of the visual solution. If the prim+ heap is used, the minimum spanning tree time complexity for each time is O (Nlog (n+m) +m) O (n l o g (n + m) + M) O (Nlog (n+m) +m), the enumeration is removed with O (n) o (n) o (n) edges, and the time complexity is O (n2lo G (n+m) +n∗m) O (n 2 L O g (n + M) + n∗m) O (N^2log (n+m) + n*m), when the figure is very dense, close to O (N3) o (n 3) O (n^3). This method is simple and intuitive, but we have a simpler and more efficient O (n2+m) O (N 2 + M) O (n^2+m) solution, which is described below.

First, the minimum spanning tree is obtained, and the sum of the recorded weights is minst. The enumeration adds each edge (u,v) (U, v) (U,V) that is not on the smallest spanning tree, plus a ring that is bound to form later. Find the second-largest edge of the weighted value on the ring (that is, except (U,v) (U, v) (U,V), the largest edge of the weight), delete it, calculate the sum of the current spanning tree weights. The minimum value of the sum of the spanning tree weights for all enumeration modifications is the sub-niche tree.

When implemented, a simpler approach is to traverse the entire minimum spanning tree from each node I, defining F[j] F [j] f[j] as the weight of the largest edge on the path from I to J. Traverse graph to find out

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.