Click to See Complete Forum and Search --> : Binary Tree manipulation


rskshiva
02-22-2005, 09:35 PM
Hi,

I need to find out number of left nodes, number of right nodes and number of pairs(Left + right) from any node of a binary tree.

Each node details is stored in database with its position(Left or right) and Parent node name or code.

How can I do this in ASP.

Kindly suggest me. It is urgent.
Providing the source code is appreciated.

Thanks.

Siva

lmf232s
02-23-2005, 10:54 AM
well since its in a DB will a SQL statement not work for you.

Select Count(LeftNode) From MyTable

Select Count(RightNode) from MyTable

Not sure about the pair, as i dont know how you decide if its a pair
but i would think this would help you solve your problem.

rskshiva
02-23-2005, 09:24 PM
Hi,

Your query will take max.only one record because, a node can have only two child nodes(one in left and one in right).

When we calculating the total left nodes for a node, it will have only one left node. we have to sum the left node of the left node...it will go upto when there is no left nodes in the tree.

same is applicable for right also.

If a node has both left and right nodes, then it is a pair, if a child node has a pair, it should calculated for its parent node also.

Hope this is clear.

Regards,
Siva R