dsa.prim module

Module to access functions for Prim’s Algorithm.

dsa.prim.mst_weight(graph)

Returns the total weight of a graph given a starting vertex

Parameters:

graph – The graph to find the total edge weight of.

Returns:

The total weight of the graph.

Return type:

int

dsa.prim.prims_mst(graph, start, mst_graph=None)

Returns an MST given a graph and starting vertex. (Future: return a Tree type instead of a Graph type)

Parameters:
  • graph – The graph to search an MST from. (can be either an AdjacencyListWeightedGraph or AdjacencyMatrixWeightedGraph)

  • start (string) – The starting vertex label.

  • mst_graph – An empty graph object to output the MST in to.

Returns:

the MST of the graph.

Return type:

AdjacencyListWeightedGraph