(node1, node2, weight)
| 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 |