Re: [algogeeks] Re: binary tree ques

2011-08-24 Thread Anantha Krishnan
Hi, We can do like this, int computeXY(Tnode *root,int x,int y) { if(root==NULL) return x; root->y=y; int l=computeXY(root->left,x,y-1); root->x=l+1; int r=computeXY(root->right,root->x,y-1); return r; } call it as, computeXY(root,-1,getHeight(root,0)-1); Thanks

Re: [algogeeks] Re: binary tree ques

2011-08-23 Thread Dheeraj Sharma
let the nodes are stored in array like arr[1] arr[2] arr[3] . . . arr[7]. where arr is a structure having int x,int y. i=1 initally we set the root(i.e arr[i]) x and y = n/2,log(n) respectively i++ then we iterate in the followin way while(i<=n) { arr[i].x=parent(arr[i]).x-1 arr[i].y=parent(arr[

Re: [algogeeks] Re: binary tree ques

2011-08-23 Thread shashi kant
an improvement to above solution take a dynamic linear array structure storing ( and y-index) and whose index tells x value of Algo:> do inorder traversal and when reach the leftmost end of the tree start updating the structure. On Wed, Aug 24, 2011 at 1:53 AM, DK wrote: > Let Left = -1, R

[algogeeks] Re: binary tree ques

2011-08-23 Thread DK
Let Left = -1, Right = +1 For each node Set: X = Sigma{Left or Right for each node on the path from root to node} Y = -Depth of the node in the tree Go through the tree once and set X and Y values using any traversal (say postorder) in an array. Also, during that traversal, find max_height and t