23.5 Weighted Graphs A weighted graph is one where a number or value is associated with each edge. These values are called weights. Insert graph The numbers in the graph above represent the distance between each town in terms of Km. Numbers in weighted graphs may also represent times, lengths, people, cost, etc.
Trees A tree is a connected graph that has no circuits. A tree does not have multiple edges nor does it have enclosed areas. A tree with n vertices has n-1 edges. Insert graph No. of vertices = 7 No. of edges = n – 1 = 7 – 1 = 6
Spanning Trees A spanning tree is a subgraph that contains all the vertices of the original graph and is a tree. A minimum spanning tree for a weighted graph is a spanning tree for which the sum of the weights of the edges is as small as possible.
Prim’s Algorithm Prim’s Algorithm is a set of rules to determine a minimum spanning tree for a graph. 1.Choose a vertex and connect to another vertex by choosing the smallest weight available. 2.In each following step, take the edge with the lowest value. 3.Repeat until all the vertices are connected then stop. 4.Calculate the sum of the weights. Insert example