473,769 Members | 5,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need an algorithm to process nodes in a tree recursively

Hi,

I have two tables 'master' and 'child', the master is the master table
for all nodes in all trees. To get children of any node, we need to go
to the 'child' table to get the nodeid of the children. The master has
about 40,000 such trees with about 400 nodes in each tree.
The input to me is the 'Root Node'/'First Node' of a tree. I need to
traverse thru all the child nodes starting from 'Root Node' ( and
process it ) and then populate my destination table 'Tree'. As an
example, here is the table structure with data for a single tree.

I will very much appreciate if anyone can give me an algorithm or
pl/sql code to do this.

SOURCE TABLES
--------------

MASTER
------
Node_id, childid, childcount
1,10,3
2,13,2
3,0,0
4,0,0
5,0,0
6,0,0

CHILD
-----
childid, nodeid, nextchildid
10,2,11
11,3,12
12,4,0
13,5,14
14,6,0

Now, Node 1 has 3 children. To get the node ids of children, We need
to traverse the CHILD table starting at childid till nextchildid
becomes 0 to get all children of node 1.

DESTINATION TABLE
-------------------

Tree
-----
Nodeid, childnodeid
1,2
1,3
1,4
2,5
2,6
3,0
4,0
5,0
6,0
Jul 19 '05 #1
0 2786

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1656
by: Tracey | last post by:
I have an algorithm question and don't know how to do it nicely. Write a function to print nodes of binary tree, for each leaf node, print nodes from root node to leaf node. For example, the following binary tree has 4 leaf nodes. 30 25 36 39 40 10 64 The resulting of print should be : 30, 25, 39
8
1755
by: jason | last post by:
Hello everyone, I am looking for an algorithm that would take an incremental value and map that to a case-inspecific alphanumeric string. However, I don't want the string to simply step through 0000, 0001 ... ZZZZ. I would ideally like the value to appear to jump around randomly, but still be traced back to an incrementing value. So, for example, while a simple standard mapping might look like: foo(1) => 0000
2
22049
by: Jack | last post by:
Hello, I am trying use a TreeView with checkboxes. I would like to check more than one node and allow all child nodes of selected nodes to be checked or unchecked with the parent is checked. Thanks in advance for any help, Jack
0
2607
by: rokuingh | last post by:
ok, so i've been working on this one for quite a while, and the code is very big so i'm just going to give the relevant parts. this is a program that builds polymers (chemical structures of repeated monomers) which are represented as doubly pointed noncomplete binary trees. There are three different types of monomers (hence the three different constructer calling functions) the first one is the "leaves" of the tree, the second adds length...
1
4681
by: satan | last post by:
I need to write the definition of the method leavesCount that takes as a parameter a reference of the root node of a binary tree and returns the numbers of leaves in the binary tree. This what i get so far public class BinaryTree { //Definition of the node protected class BinaryTreeNode { DataElement info;
6
1715
by: Designing Solutions WD | last post by:
I have the following table. GO /****** Object: Table . Script Date: 05/01/2007 10:42:31 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO
0
1159
by: Brishti09 | last post by:
I am tring to search for an existing nodes in tree view and change its forecolor. I am matching the tag value of the node. The program is able to search recursively through the tree and change the forecolor of the node but the tree duplicate itself every time it searches for a node... in my recursive function I am only checking for the forecolor NOT adding any nodes.... I have no clue why the whole tree is being duplicated everytime i am...
0
274
by: Dinesh | last post by:
Hi, I have two tables 'master' and 'child', the master is the master table for all nodes in all trees. To get children of any node, we need to go to the 'child' table to get the nodeid of the children. The master has about 40,000 such trees with about 400 nodes in each tree. The input to me is the 'Root Node'/'First Node' of a tree. I need to traverse thru all the child nodes starting from 'Root Node' ( and process it ) and then...
0
1426
by: dogatemycomputer | last post by:
I'm new to C#. I am using the following C# method to populate a TreeView control. If you call this method once during the life of form then it works perfectly. If you call the method a second time (without closing and reloading the app) then the process list populates the TreeView control with varying degrees of success. Sometimes the process name shows up (or not), threads that can load modules are red while others are not and...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.