Tree Structure:
0 (root)
/ \
1 2
/ \
3 4
means: node has no parent (root), nodes and have parent , nodes and have parent .
Query : . Find the st ancestor of node
- (binary), bit is set
- Jump step:
node = up[3][0] = 1 - Result: (parent of )
Query : . Find the nd ancestor of node
- (binary), bit is set
- Jump steps:
node = up[3][1] = 0 - Result: (grandparent of )
Query : . Find the rd ancestor of node
- (binary), bits and are set
- Jump step:
node = up[3][0] = 1 - Jump steps:
node = up[1][1] = -1(no such ancestor) - Result: (node doesn't have a rd ancestor)