473,756 Members | 8,110 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 2784

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
22045
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
9275
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
10040
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...
0
9873
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9846
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
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
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
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3806
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

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.