MCPcopy
hub / github.com/TheAlgorithms/JavaScript / addEdge

Method addEdge

Graphs/BinaryLifting.js:29–39  ·  view source on GitHub ↗
(node1, node2)

Source from the content-addressed store, hash-verified

27 }
28
29 addEdge(node1, node2) {
30 // Function to add an edge (adds the node too if they are not present in the tree)
31 if (!this.connections.has(node1)) {
32 this.addNode(node1)
33 }
34 if (!this.connections.has(node2)) {
35 this.addNode(node2)
36 }
37 this.connections.get(node1).add(node2)
38 this.connections.get(node2).add(node1)
39 }
40
41 dfs(node, parent) {
42 // The dfs function calculates 2^i-th ancestor of all nodes for i ranging from 0 to this.log

Callers 1

constructorMethod · 0.95

Calls 4

addNodeMethod · 0.95
hasMethod · 0.45
addMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected