Math 3614, Homework 4

Instructions: The following assignment is due Wednesday 12/11/96. Late papers will be accepted until 5:30 pm Friday 12/13/96 at a 10\% penalty. No assignments will be accepted after 12/13/96. You may discuss the assignment with other students in the class, but anywork you turn in must be your own.

Write a program that uses Prim's algorithm to find a minimal spanning tree for a weighted simple connected undirected graph. Input will be a list of edges and weights (prompt the user to enter these); output will be the edges in the order chosen and the total weight of the spanning tree. Test your program on the following test cases: (The first two numbers in each triple represent the vertices connected by the edge, and the third number is the weight of the edge).

  1. 1,2,5; 1,3,6; 1,4,5; 1,7,6; 2,3,4; 2,6,4; 3,4,6; 3,6,8; 3,7,7; 4,5,7; 4,6,6; 5,6,3; 6,7,2

    NOTE: the output for this input should look like:

    Edges: (6,7), (6,5), (6,2), (2,3), (2,1), (1,4) 
    Total weight of this spanning tree is 23.
    
  2. 1,2,3; 1,3,2; 2,3,4; 2,4,2; 3,4,3; 3,5,2; 4,5,5; 5,6,4; 5,8,5; 6,7,5; 7,8,4

  3. 1,2,3; 1,4,10; 1,5,2; 2,3,4; 2,5,9; 3,5,6; 3,6,5; 4,5,4; 4,7,4; 5,6,3;
    5,7,6; 5,8,3; 5,9,6; 6,9,6; 7,8,8; 7,10,3; 8,9,8; 8,10,3; 8,11,5; 8,12,7;
    9,12,4; 10,11,5; 11,12,2