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[i]).y-1

i++;


arr[i].x=parent(arr[i]).x+1
arr[i].y=parent(arr[i]).y-1
}

Thus all node structures will contain there x and y coordinate..
m nt sure..bt it can work
On Wed, Aug 24, 2011 at 10:34 AM, shashi kant <[email protected]>wrote:

> an improvement to above solution
>
> take a dynamic linear array structure storing (<node name> and y-index) and
> whose index tells x value of <NodeName>
>
> 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 <[email protected]> wrote:
>
>> 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 the number of nodes in
>> the left subtree of root.
>>
>> Go through the array and output: <Node Name> (<X +
>> num_left_nodes_of_root>, <Y + max_height>)
>>
>> --
>> DK
>>
>> http://gplus.to/divyekapoor
>> http://twitter.com/divyekapoor
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/algogeeks/-/qp4FZ3vE5WcJ.
>>
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> *Shashi Kant *
> ***"Think positive and find fuel in failure"*
> *+919002943948*
> Final Yr. Cse ,Undergraduate Student,
> *National Institute Of Technology Durgapur.*
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*Dheeraj Sharma*
Comp Engg.
NIT Kurukshetra
+91 8950264227

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to