Hierarchy

  • Prim

Constructors

Methods

  • Helper method to add edges from a vertex to the edge list Note: This implementation sorts the edges array on each iteration. For better performance with large graphs, consider using a proper priority queue data structure (e.g., binary heap).

    Parameters

    • graph: WeightedGraph
    • vertex: string
    • visited: Set<string>
    • edges: Edge[]

    Returns void

  • Converts an edge list to a weighted graph (adjacency list)

    Parameters

    • edges: Edge[]

      array of edges

    Returns WeightedGraph

    weighted graph as adjacency list

  • Finds the Minimum Spanning Tree using Prim's algorithm

    Parameters

    • graph: WeightedGraph

      weighted graph as adjacency list

    • Optional start: string

      starting vertex (optional, uses first vertex if not provided)

    Returns MSTResult

    object containing MST edges and total weight

  • Finds MST from edge list format

    Parameters

    • vertices: string[]

      array of vertex names

    • edges: Edge[]

      array of edges

    Returns MSTResult

    object containing MST edges and total weight

Generated using TypeDoc