Graph theory-minimum spanning tree (MST) algorithm __ algorithm

Source: Internet
Author: User
Min Spanning tree: E = V-1
The minimum spanning tree of the unauthorized graph does not need to care about the length of the edge, but to find the least number of edges.
The minimum spanning tree is almost identical to the search algorithm and can also be given depth-first search and breadth-first search.
The DFS algorithm accesses all vertices, but accesses only once and never accesses the same vertex two times. When you see a certain edge
is going to reach an already visited vertex, it will not go this side. So the DFS algorithm passes through the path of the whole diagram must
Is the minimum spanning tree.
The improvement to the DFS algorithm is to simply output the current vertex in the Else
public void MST () {
    	stack<integer> Stack = new stack<integer> ();
    	Start accessing the first vertex
    	varr[0].isvisited = true;
    	Into the stack
    	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); Displays the current vertex
    			Disvertex (v);     Shows the adjacency point, the edge of the two vertices is the side 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.