Skip to content

Commit 92e09c4

Browse files
committed
Revise LCA visualization
1 parent 8ec07b2 commit 92e09c4

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 8 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy