Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 binary tree

Author  Topic 

jiyajk
Starting Member

1 Post

Posted - 2010-10-26 : 01:16:07
Hi
I have a table which stores data in the binary tree structure format.

The issue here is : when the total number of child nodes of a node is 14, then the same node should be inserted in the tree as a child node. This goes for each node of the binary tree.

E.g.; consider the root node 002. After the child node 051 has been inserted, the number of child nodes of 002 will be 14 and then the node 002 should be automatically added as a child node in the binary tree.

And then for the next node 005, the total number of child nodes becomes 14 (after the child 095 has been inserted), 005 should be automatically inserted as a child node in the tree and this process goes on…

Userid Parentid
002 0
005 002
007 002
010 005
014 005
017 007
020 007
027 010
030 010
034 014
035 014
040 017
043 017
048 020
051 020

002 027
056 027
067 030
075 030
083 034
088 034
090 035
095 035

005 040

In this table, Userid is the foreign key. In the table where Userid is a primary key, Userid is an IDENTITY column.

can anyone please let me know the stored procedure logic for getting the solution for the above?


- Thanks in advance

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-10-26 : 03:20:48
Lumbago, where is your previous answer?



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -