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

Method dfsDepth

Graphs/LCABinaryLifting.js:19–27  ·  view source on GitHub ↗
(node, parent)

Source from the content-addressed store, hash-verified

17 }
18
19 dfsDepth(node, parent) {
20 // DFS to find depth of every node in the tree
21 for (const child of this.connections.get(node)) {
22 if (child !== parent) {
23 this.depth.set(child, this.depth.get(node) + 1)
24 this.dfsDepth(child, node)
25 }
26 }
27 }
28
29 getLCA(node1, node2) {
30 // We make sure that node1 is the deeper node among node1 and node2

Callers 1

constructorMethod · 0.95

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected