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 of first 'i' terms of GP is greater than your N. On Mon, Aug 1, 2011 at 4:56 PM, Douglas <douglas.han...@gmail.com> wrote: > 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 is my approach: > > > > Suppose index is the index given and we have to find its depth .Also the > > tree is N ary > > > > int i=1; > > while(index > 0) > > { > > index=index-N^i; > > i++;} > > > > return index; > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Cheers, Ram -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.