Functions
The following functions are available globally.
-
Gives the shortest path from one vertex to another in an unweighted graph.
Declaration
Swift
public func breadthFirstPath<G: Graph, V: Hashable where V == G.Vertex>( graph: G, start: V, end: V) -> [V]?
Parameters
graph
The graph in which to search.
start
The vertex from which to start the BFS.
end
The destination vertex.
Return Value
An optional array that gives the shortest path from start to end. returns nil if no such path exists.
-
Runs Prim’s algorithm on a weighted undirected graph.
Declaration
Swift
public func primsSpanningTree<G: WeightedGraph where G.Vertex: Hashable>( graph: G) -> G
Parameters
graph
A weighted undirected graph for which to create a minimum spanning tree.
Return Value
A minimum spanning tree of the input graph.