472,965 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,965 software developers and data experts.

Need Algorithm or Data Structure for Organizing "Hierarchical" Data

Hello:

I have a bunch of related items that are either parents, children or
not directly related to each other. In my case, I have a bunch of
database tables joined with foreign keys. Another example would be a
family tree.

I would like to take a flat list of these items and build the
hierarchy. So, in other words, I would like to take one element and
figure out its relationship to the other items. When I am all done, I
should have a somewhat complex structure.

I want to allow situations such as: I am my own grandpa; I have
multiple children; I have multiple parents; I'm completely unrelated
to this guy.

If the resulting structure can't be iterated over, I am willing to
eliminate the "I am my own grandpa" situation. It's not necessary,
just nice.

I would want all orphaned items to be at the top level. All the
children of these elements can be at the next level. And so on . . .

I would like to require the algorithm or data structure to take a
Comparison<Tdelegate to determine rank between two items.

I would like to provide iterators that do breadth-first, depth-first,
etc. However, so long as parent and child relationships are many-to-
many, I don't think iteration is feasible. Grouping is always an
option.

My throught was to take a new item and pass it to the comparison
delegate for each existing item in the data structure. I would keep a
list of parents and a list of children. I would then create a child
"node" under the parents. I would create a child "node" under the new
node foreach child.

However, unless I chop off requirements, I feel like this is a very
complex problem. I was wondering if anyone knew of an algorithm or
data structure that did something similar. I would rather not reinvent
the wheel.
Jul 4 '08 #1
2 3935
What you need is a graph. You can iterate over it with either a depth-first
or breadth-first search.

I wrote some classes to do this. You can download the documentation (as a
PDF) for free, as well as the source code.
http://www.lulu.com/content/1995848

You can find other implementations/ideas by searching the net.
<je**********@gmail.comwrote in message
news:ff**********************************@i76g2000 hsf.googlegroups.com...
Hello:

I have a bunch of related items that are either parents, children or
not directly related to each other. In my case, I have a bunch of
database tables joined with foreign keys. Another example would be a
family tree.

I would like to take a flat list of these items and build the
hierarchy. So, in other words, I would like to take one element and
figure out its relationship to the other items. When I am all done, I
should have a somewhat complex structure.

I want to allow situations such as: I am my own grandpa; I have
multiple children; I have multiple parents; I'm completely unrelated
to this guy.

If the resulting structure can't be iterated over, I am willing to
eliminate the "I am my own grandpa" situation. It's not necessary,
just nice.

I would want all orphaned items to be at the top level. All the
children of these elements can be at the next level. And so on . . .

I would like to require the algorithm or data structure to take a
Comparison<Tdelegate to determine rank between two items.

I would like to provide iterators that do breadth-first, depth-first,
etc. However, so long as parent and child relationships are many-to-
many, I don't think iteration is feasible. Grouping is always an
option.

My throught was to take a new item and pass it to the comparison
delegate for each existing item in the data structure. I would keep a
list of parents and a list of children. I would then create a child
"node" under the parents. I would create a child "node" under the new
node foreach child.

However, unless I chop off requirements, I feel like this is a very
complex problem. I was wondering if anyone knew of an algorithm or
data structure that did something similar. I would rather not reinvent
the wheel.

Jul 4 '08 #2
On Jul 4, 3:40*am, "Fred Mellender" <nospamPlease_fred...@gmail.com>
wrote:
What you need is a graph. *You can iterate over it with either a depth-first
or breadth-first search.

I wrote some classes to do this. *You can download the documentation (as a
PDF) for free, as well as the source code.http://www.lulu.com/content/1995848

You can find other implementations/ideas by searching the net.
I was actually able to avoid the graph data structure by making it
illegal for nodes to be their own ancestors. The algorithm I came up
with is still insanely slow for large data sets: O(n2 + n*lg(n) + 2n).
I am not sure how to build such a structure without each node looking
at each other at least once.

Thanks for your help,
Travis
Jul 9 '08 #3

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

Similar topics

1
by: Bruce W.1 | last post by:
I want an XML file to describe hierarchical data where each node is different. Each node will contain different and varied other nodes. Describing this in an XML file would be easy but I'm having...
3
by: neverstill | last post by:
So I thought I had a solution to my problem using DataRelations with the DataSet. I need to display hierarchical data. I have a DataList nested into another DataList. My datasource is a...
0
by: PontiMax | last post by:
I'm working with the Northwind database tables 'Customers', 'Orders', and 'Order Details': 'CustomerID' relates 'Orders' to 'Customers', and 'OrderID' relates 'Order Details' to 'Orders'. For...
5
by: Kent Boogaart | last post by:
Hi, I have some hierarchical data (FAQs) that I would like to bind to. The basic structure is: FAQ Category + Categories + FAQs So an FAQ category has any number of sub-categories and any...
4
by: Congero | last post by:
I'm trying to find a way to bind hierarchical data to a gridview control. I've been able to do this with some third party controls and was wondering if this functionality is available with the...
0
by: goran | last post by:
Hello! I've discovered a new approach to storing ordered hierarchical data in RDBs. As far as I know there is no similar model out there and it differs significantly from traditional models...
0
by: MeMySelf | last post by:
i have a problem when i want create Hierarchical Data..please help me to solve this problem..i would be thanks fully if you can explain step by step using this tools (Janus Web GridEX)..thnX
4
by: ranu2006 | last post by:
Hi All, I want to write a stored procedure that can fetch Hierarchical data from a table I will be passing Employee Name and I want to fetch his seniors employees and his junior employees ...
0
by: amodagni | last post by:
Hi ! Could someone please guide me to SQL code required for managing data in tables in which hierarchical data stored in adjacency or Nested set model.
4
by: Marco Pais | last post by:
Hi there. I am trying to find th best way (best UI control) to present hierarchical data, nested tables. For example, I have a Employees table (id, name) and EmployeesSales (id, idEmp,...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.