MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / addEdge

Method addEdge

Graphs/PrimMST.js:13–23  ·  view source on GitHub ↗
(node1, node2, weight)

Source from the content-addressed store, hash-verified

11 }
12
13 addEdge(node1, node2, weight) {
14 // Function to add an edge (adds the node too if they are not present in the graph)
15 if (!(node1 in this.connections)) {
16 this.addNode(node1)
17 }
18 if (!(node2 in this.connections)) {
19 this.addNode(node2)
20 }
21 this.connections[node1][node2] = weight
22 this.connections[node2][node1] = weight
23 }
24
25 PrimMST(start) {
26 // Prim's Algorithm to generate a Minimum Spanning Tree (MST) of a graph

Callers 1

PrimMSTMethod · 0.95

Calls 1

addNodeMethod · 0.95

Tested by

no test coverage detected