Skip to content

Commit 52dbc4c

Browse files
author
Raghav Dua
authored
Merge pull request algorithm-visualizer#210 from archie94/lca-revise
Revise LCA visualization
2 parents dc1ceda + 92e09c4 commit 52dbc4c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

algorithm/tree/lowest_common_ancestor/binary_tree/code.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ function lcaBT (parent, root, a, b) {
2121
return (left !== null ? left : right);
2222
}
2323

24-
var a = 7, b = 9;
24+
var a = 7, b = 2;
2525
logger._print ('Lowest common ancestor of ' + a + ' & ' + b + ' is: ' + lcaBT (null, 5, a, b));

algorithm/tree/lowest_common_ancestor/binary_tree/data.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
var G = [ // G[i][j] indicates whether the path from the i-th node to the j-th node exists or not
22
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3-
[1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
3+
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
44
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
5-
[0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0],
5+
[0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0],
66
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
77
[0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0],
8-
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
8+
[1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
99
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
10-
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1],
10+
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1],
1111
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
1212
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
1313
];
1414

1515

1616
var T = [ // mapping to G as a binary tree , [i][0] indicates left child, [i][1] indicates right child
1717
[-1,-1],
18-
[ 0, 2],
18+
[-1, 7],
1919
[-1,-1],
20-
[ 1, 4],
20+
[ 6, 1],
2121
[-1,-1],
2222
[ 3, 8],
23-
[-1, 7],
23+
[ 0, 2],
2424
[-1,-1],
25-
[ 6,10],
25+
[10, 4],
2626
[-1,-1],
2727
[ 9,-1]
2828
];

0 commit comments

Comments
 (0)