Skip to content

@graphty/algorithms / index / primMST

Function: primMST() ​

primMST(s, o?): PrimResult

Defined in: indexed/mst.ts:102

Prim's minimum spanning tree, grown from a start node by always taking the cheapest arc from the tree to a node outside it (an indexed heap keyed per node, so of several parallel edges the cheapest, and of equal ones the lowest-indexed, is the one taken). edges lists the logical edges in the order they joined the tree and totalWeight sums them in that order, as legacy primMST does. The start index is checked: one outside the graph throws a RangeError.

Parameters ​

s ​

GraphSnapshot

An undirected snapshot

o? ​

PrimOptions = {}

Per-arc weight override, start node and the spanning-forest switch

Returns ​

PrimResult

The accepted edges, their total weight and the discovery arc per node

Throws ​

Error on a directed snapshot, and on a disconnected one unless forest is set