数据结构之图-无权图的最小生成树(7)
2013-03-11 13:15
561 查看
1 Unweighted Graphs
For unweighted Graphs, a minimum spanning tree(MST) means that a graph with minimum number of edges to connect all the vertices.
the number of edges E in a minimum spanning tree is always one less than the number of vertices V: E = V – 1.
The path of the
DFS(depth-first search) through the graph must be a minimum spanning tree.
1.1 Java implement
For unweighted Graphs, a minimum spanning tree(MST) means that a graph with minimum number of edges to connect all the vertices.
the number of edges E in a minimum spanning tree is always one less than the number of vertices V: E = V – 1.
The path of the
DFS(depth-first search) through the graph must be a minimum spanning tree.
1.1 Java implement
public void mst() // minimum spanning tree (depth first) { // start at 0 vertexList[0].wasVisited = true; // mark it theStack.push(0); // push it while( !theStack.isEmpty() ) // until stack empty { // get stack top int currentVertex = theStack.peek(); // get next unvisited neighbor int v = getAdjUnvisitedVertex(currentVertex); if(v == -1) // if no more neighbors theStack.pop(); // pop it away else // got a neighbor { vertexList[v].wasVisited = true; // mark it theStack.push(v); // push it // display edge displayVertex(currentVertex); // from currentV displayVertex(v); // to v System.out.print(" "); } } // end while(stack not empty) // stack is empty, so we're done for(int j=0; j<nVerts; j++) // reset flags vertexList[j].wasVisited = false; } // end mst()
相关文章推荐
- 算法与数据结构(五) 普利姆与克鲁斯卡尔的最小生成树(Swift版)
- 数据结构——最小生成树Prim算法
- 2144 数据结构实验之图论九:最小生成树
- 数据结构——构造最小生成树
- 数据结构(最小生成树)
- 数据结构之 图论---最小生成树(prim + kruskal)
- 数据结构实验之图论九:最小生成树
- 2144-数据结构实验之图论九:最小生成树
- 数据结构——图常用算法实现(DFS,BFS,最小生成树,最短路径,拓扑序列)
- 数据结构(C实现)------- 最小生成树之Prim算法
- 数据结构之图(四)——最小生成树
- 【数据结构】求最小生成树的权值之和——Prim算法
- 数据结构之(prim)最小生成树
- 数据结构——邻接矩阵的最小生成树Prim算法
- 数据结构与算法问题 北大oj 2075(最小生成树)
- 数据结构之---C语言实现最小生成树之prim(普里姆)算法
- 暑假集训 8.18 数据结构实验之图论六:村村通公路 (最小生成树)
- 数据结构之 图的最小生成树
- 实用数据结构---最小生成树(克鲁斯卡尔实现)
- SDUT 3362-数据结构实验之图论六:村村通公路(最小生成树_prim)