CPS 100, Spring 2004

Minimum Spanning Trees

A spanning tree is one that includes all the vertices within a graph such that the graph is fully connected and contains no cycles. Sometimes it is important to know the minimumal spanning tree of a graph, i.e., a spanning tree such that the sum of the the weights of all the edges in the spanning tree is the smallest possible.
  1. How many edges are there in a minimum spanning tree (or any spanning tree in general)?
    
    
    
    
  2. In general, there may be more than one minimum spanning tree for a single graph. Draw a simple graph that has more than one minimum spanning tree.
    
    
    
    
    
    
    
    
    
    
    
    
  3. The heart of Prim's algorithm for finding minimal spanning trees is given below (enough to reason about the complexity), the entire program that calculates the tree is in prim.cpp

    What is the complexity of this algorithm on a graph with V vertices and E edges? You should write an expression in terms of both E and V, e.g., something like O(E + V log V). Assume that the priority queue never has more than V elements in it.

    tpqueue<VertDist> pq; int k; tvector<string> verts, adj; // insert all vertices into priority queue with distances // of infinity, except for vertex 0 which has distance 0 int vertex; VertDist vd; while (pq.size() > 0) { pq.deletemin(vd); vertex = vd.vertex; if (!myState[vertex].visited) { myState[vertex].visited = true; myGraph.getAdjacent(myGraph.getName(vertex), adj); for(k=0; k < adj.size(); k++) { int index = myGraph.getNum(adj[k]); if (! myState[index].visited) { double weight = myGraph.getWeight(vertex, index); if (weight < myState[index].distance) { myState[index].distance = weight; myState[index].path = vertex; pq.insert(VertDist(index,myState[index].distance)); } } } } }
  4. In fact, there may be more than V vertex in the priority queue at any given time. Why? What is the maximum number of vertices that could in the priority queue? Does this affect the time complexity you computed above?


jeff
Last modified: Fri Apr 16 13:02:04 EDT 2004