File tree 1 file changed +8
-1
lines changed
1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
2
* Author: Adrito Mukherjee
3
+ * @class BinaryLifting
3
4
* Binary Lifting implementation in Javascript
4
- * Binary Lifting is a technique that is used to find the kth ancestor of a node in a rooted tree with N nodes
5
+ * @classdesc Binary Lifting is a technique that is used to find the kth ancestor of a node in a rooted tree with N nodes
5
6
* The technique requires preprocessing the tree in O(N log N) using dynamic programming
6
7
* The technique can answer Q queries about kth ancestor of any node in O(Q log N)
7
8
* It is faster than the naive algorithm that answers Q queries with complexity O(Q K)
10
11
*/
11
12
12
13
export class BinaryLifting {
14
+ /**
15
+ * Creates an instance of BinaryLifting.
16
+ * @template T
17
+ * @param {T } root
18
+ * @param {Array<[T, T]> } tree - The edges of the tree represented as an array of pairs.
19
+ */
13
20
constructor ( root , tree ) {
14
21
this . root = root
15
22
this . connections = new Map ( )
You can’t perform that action at this time.
0 commit comments