Graph Theory-Minimum Spanning Tree (MST) Algorithm

Source: Internet
Author: User

Min Spanning Tree: E = V-1
The minimum spanning tree of a no-Permission graph does not need to care about the edge length, but needs to find the minimum number of edges.
The Minimum Spanning Tree is almost the same as the search algorithm, and can also be used for deep and breadth-first searches.
The DFS algorithm only accesses all vertices once and never accesses the same vertex twice. When you see an edge
It is about to reach an accessed vertex, so it will not go through this edge. Therefore, the DFS algorithm must go through the path of the entire graph.
Is the Minimum Spanning Tree.
The DFS algorithm is improved, but the current vertex is output in else.

Public void MST () {stack <integer> stack = new stack <integer> (); // access the first vertex varr [0]. isvisited = true; // stack. push (0); While (! Stack. isempty () {int currv = stack. peek (); int v = getunvisitedvertex (currv); If (V =-1) {stack. pop ();} else {varr [v]. isvisited = true; stack. push (V); disvertex (currv); // display the current vertex disvertex (V); // display adjacent contacts, the edges composed of these two vertices are the edges of the MST} reset ();}

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.