Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have table like
HTML
ChildNode    ParentNode    LorR
     1       NULL         NULL
     2       1              0
     3       1              1
     4       2              0
     5       2              1
     6       3              0
     7       3              1
     8       4              0
     9       4              1
     10      5              0
     11      6              0
     12      7              1

this table data define Binary Tree Data
first node is 1
LorR define child is ini left(0) or Right(1)
1 st node has two child node 2 and 3 in Left and Right
2 nd node has two child node 4 and 5 in Left and Right
3 rd node has two child node 6 and 7 in Left and Right
4 th node has two child node 8 and 9 in Left and Right
5 th node has one child node 10 in Left
6 th node has one child node 11 in Left
7 th node has one child node 12 in Right

now if i want to find the number of total child nodes of any parent node
for ex...node 2 (parent) has a 4 child (4,5,8,9)
node 6 (parent) has a 1 child (11)
node 3 (parent) has a 4 child (6,7,11,12)

then As a parameter Parent node how can i get the number of Child and subchild nodes


also how can i find total number of Left Child's subchild nodes...

please help....
Posted

Since you need the total amount of children, have a look at CTE. For example: http://msdn.microsoft.com/en-us/library/ms175972.aspx[^].

CTE can be used to create a recursive query so you can use that even if you don't know the amount of child levels beforehand.
 
Share this answer
 
Use this link and apply the algorithm.Hope this may help you.

http://www.mindcracker.com/Story/330/a-question-a-day-count-leaf-nodes-in-a-binary-tree[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900