MCPcopy Create free account
hub / github.com/loiane/javascript-datastructures-algorithms / minKey

Function minKey

src/13-graph/prim.js:3–13  ·  view source on GitHub ↗
(graph, key, visited)

Source from the content-addressed store, hash-verified

1const INF = Number.MAX_SAFE_INTEGER;
2
3const minKey = (graph, key, visited) => {
4 let min = INF;
5 let minIndex = 0;
6 for (let v = 0; v < graph.length; v++) {
7 if (visited[v] === false && key[v] < min) {
8 min = key[v];
9 minIndex = v;
10 }
11 }
12 return minIndex;
13};
14
15const prim = (graph) => {
16 const parent = []; // Stores the MST

Callers 1

primFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected