Skip to content

eles.kruskal(weight?)

eles.kruskal — Collection > Algorithms > Spanning. Cytoscape.js signatures, parameters and return contract.

eles.kruskal — Collection › Algorithms › Spanning

Preview · Collection › Algorithms › Spanning

Read in the complete API reference · All API members

// Build a minimum spanning forest of this collection, treating its edges as undirected
eles.kruskal(weight?: WeightFn): Collection<NodeData, EdgeData>

Build a minimum spanning forest of this collection, treating its edges as undirected. Equal-weight edges retain collection order. Disconnected input produces one tree per connected component.

Parameters
NameDescription
weight: WeightFn?

(edge) => number; defaults to unit weights

Returns Collection<NodeData, EdgeData>

a collection containing all input nodes and the accepted forest edges, in acceptance order

Example

const forest = eles.kruskal(edge => edge.data('weight'));
console.log(forest.edges().length); // 2

Example graph and handle setup