d
of the tree (distance from the root to the deepest node).d
is 0, meaning the tree has only one node, return 1.2^d - 1
.exists
to check if a node at that index exists.exists
function will simulate the path from the root to the node index and check if the node is present.2^d - 1
plus the number of nodes found in the last level.