Talk:UVa 679

From Algorithmist
Jump to navigation Jump to search

ONE SOLUTION In any sub-tree, even numbered ball to that sub-tree's root goes to right and odd numbered to the left. So using this fact we can make following function

int subtree(int depth ,int i,int root) {

       return root;
   else if(i%2==0)
       return subtree(depth-1,i/2 , 2*root+1);
       return subtree(depth-1, (i+1)/2 , 2*root);


Link : Online Compiler