Log(N+1) works only for binary tree(lg(N+1). For N-ary tree the formula is a
little different.
Height of node K = floor( Log N ( (N-1)*K ) )
For binary tree it translates to floor(lgN)
Note: I've assumed node index begin from 1 rather than 0
Regards,
Sandeep Jain
On Mon, Aug 1, 2011 at
Thanks Abhishek, but I am not looking for an iterative solution. I am
looking for a formula, if possible.
On Aug 1, 11:28 am, Abhishek Gupta gupta.abh...@gmail.com wrote:
Subtract n-1,(n^2) - 1,(n^3)-1 until index is = 0 and so on from the given
index.
i think following code should work.
Thanks Ankit, but I am not looking for an iterative solution. I am
looking for a formula, if possible, rather than a funtion. If I can't
find an analytical formula I will revert to an iterative/recursive
function.
On Aug 1, 11:55 am, ankit sambyal ankitsamb...@gmail.com wrote:
@Douglas: Here
If you want to find out the depth of node number N then it would be log (N
+1 )..
Explanation:
Number of terms at each level follows GP i.e.,
1 2 4 8 16 32 . and so on.
Number of nodes in tree till depth 'i': Take the sum of GP till 'ith'
term.
So your task is to find the 'i' such that sum