Sub-niche tree-forming algorithm

Source: Internet
Author: User

For a undirected band-edge connected graph G (v,e), we can certainly extract the smallest spanning tree, then how to get the sub-niche into a tree? In graph G, the effective spanning tree set is Z, and T is the lowest total weight in g, so the tree with the smallest total weight in G\{t} is the sub-niche tree.

We may as well first consider such a problem, remember T is the smallest spanning tree in Figure G, because the spanning tree is | The v|-1 edge is the only decision, so we can assume that T represents the set of edges in the smallest spanning tree. It is easy to find that the sub-niche into a tree must contain an edge of the e\t, we can enumerate the edge e in each e\t, and the end point of E is merged, on this basis run the Kruskal or prim algorithm, find a new spanning tree, and add e to the spanning tree, We get all the least weight spanning trees in the spanning tree with E, and we call this tree the smallest spanning tree with E . It is possible to find the smallest spanning tree in these trees as a secondary niche tree, but the efficiency is very moving and the time complexity is O (| e|-| v|) *| V|LOG2 (| v|)).

In fact can be in O (| E|LOG2 (| v|)) Time complexity found in the sub-niche into a tree.

First we need to find the minimum spanning tree T. Then we enumerate each edge in E\t E, add E to T, and there must be a ring in T, and the ring contains E (| v| Edge Connected graph must have a ring), in order to make t become a legitimate tree, we need to remove an edge in the ring, obviously we should not remove E (otherwise why join it?). ), we want to remove the most weighted edge T in the ring, and then T becomes a generation tree T ' again. The Guaranteed Tree T ' is a minimum spanning tree with E, in fact we have merged the two endpoints of E to get a new figure G ', the smallest spanning tree in Figure G ' must be T ' \{e}, this is because we run the Kruskal algorithm on it, all weights less than t edge will be selected as usual, And after the completion of the edge processing of the weight less than T, the original E ring is also missing an edge T, because the spanning tree is not allowed to have a ring, so T will not be joined, to this isolated connected sub-map and establish a minimum spanning tree on G no two. So T ' \{e} is the smallest spanning tree on G '. If T ' is not a G containing the e minimum spanning tree, then there is an e spanning Tree f ', but F ' \e is also a spanning tree of G ', which means that the total weight of f ' \e is less than T ' \e, which is inconsistent with the minimum spanning tree of T ' \e is G ', so t ' is the smallest spanning tree in G

So how is the O (| E|LOG2 (| v|)) Time complexity to complete all of the above operations, we just for each side of E, can be log2 (| v|) Time complexity quickly calculates the largest edge on the path between the ends of E in the smallest spanning tree. Such algorithms are present and can be implemented using LCT (dynamic tree).

The time complexity for finding the smallest spanning tree is O (| V|LOG2 (| v|), and the build time complexity of establishing LCT on the minimum spanning tree is O (| V|LOG2 (| v|)), the time complexity of finding the minimum spanning tree with E for all sides E on the e\t is O (| e|-| v|) LOG2 (| v|)), so the total time complexity is O (| E|LOG2 (| v|).

Sub-niche tree-forming algorithm

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.