473,811 Members | 3,256 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

generic tree pathfinding

Hi, having a class like the following

class node
{
int nodeID;
list<node> listOfChildren;
list<node> listOfParents;
}

what is the smartest/fastest way to find the nearest common parent given
any 2 nodes?

i thought about using Djikstra alg. any other possibilities?

thanks a lot

Jul 19 '05 #1
2 3534

"Nevyn" <ne***********@ hotmail.com> wrote in message
news:pa******** *************** *****@hotmail.c om...
Hi, having a class like the following

class node
{
int nodeID;
list<node> listOfChildren;
list<node> listOfParents;
}
I think you mean

class node
{
int nodeID;
list<node*> listOfChildren;
list<node*> listOfParents;
};

what is the smartest/fastest way to find the nearest common parent given
any 2 nodes?
How do you define nearest common parent? Suppose there's a common parent 1
away from one node and 4 away from the other node, it that nearer or further
than one which is 2 away from both nodes?

i thought about using Djikstra alg. any other possibilities?

thanks a lot

Presumably parent nodes are found by following parent links only? Presumably
the parent links and child links are reciprocal?

Assuming the above to be true it strikes me that you are looking for the
shortest path between the two nodes (in some sense) which consists of a
sequence of parent links followed by a sequence of child links (or vice
versa), the node where you switch from parent links to child links being the
common parent.

I would consider a simple breadth first search, the A* algorithm for
instance. But really it all depends on the nature of your graph (which is
not a tree I think).

john
Jul 19 '05 #2
On Thu, 14 Aug 2003 06:47:29 +0100, John Harrison wrote:
I think you mean

class node
{
int nodeID;
list<node*> listOfChildren;
list<node*> listOfParents;
};

obviously ;-)
but it was pretty late at night when i wrote it :-)
what is the smartest/fastest way to find the nearest common parent
given any 2 nodes?


How do you define nearest common parent? Suppose there's a common parent
1 away from one node and 4 away from the other node, it that nearer or
further than one which is 2 away from both nodes?


good question... :-)
i forgot to tell that it is not possible for 2 different nodes to have the
same 2 children, so 2 node (above) can share at most 1 children
Presumably parent nodes are found by following parent links only?
Presumably the parent links and child links are reciprocal?
again, yes and yes
Assuming the above to be true it strikes me that you are looking for the
shortest path between the two nodes (in some sense) which consists of a
sequence of parent links followed by a sequence of child links (or vice
versa), the node where you switch from parent links to child links being
the common parent.

I would consider a simple breadth first search, the A* algorithm for
instance. But really it all depends on the nature of your graph (which
is not a tree I think).


well, i'll try to be clearer and state the problem more precisely this
time.
i built this graph from archeological data, where each node represent an
excavation stratum which is under some and above others. now, two strata
might share an horizontal relationship, that is they must be as close as
possible on the same level. e.g.

A
|_______
| | |
B C D

if there is a Hrelation between B & D i have to show

A
|______
| | |
B D C
or if

A
|__________
| | |
B D C
|_ | |_
| | E | |
F G H I

suppose the relation is between G&I
the desired result is

A
|__________
| | |
B C D
|_ |_ |
| | | | E
F G I H

so my idea was:
find the closest common parent (A in this case) move the appropriate
sub-trees (B,D and their descendants) in the right direction

i used a depth-first alg., but it fails if there is more than one path to
one of the 'h related' stratums

Hope i had been clearer this time :-)
thanks a lot
Jul 19 '05 #3

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

Similar topics

49
2905
by: Steven Bethard | last post by:
I promised I'd put together a PEP for a 'generic object' data type for Python 2.5 that allows one to replace __getitem__ style access with dotted-attribute style access (without declaring another class). Any comments would be appreciated! Thanks! Steve ----------------------------------------------------------------------
18
3055
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of a single collections type, I should be proposing a new "namespaces" module instead. Some of my reasons: (1) Namespace is feeling less and less like a collection to me. Even though it's still intended as a data-only structure, the use cases...
4
1708
by: Ben | last post by:
Hi, I was writing a expression template for string concatenation latetly. When writing it, I started to feel curious that why there's not any generic et lib that can save me from wring each different et lib from scratch. Or, maybe I was just ignorant and there is some already? matrix, string, array, vector, whatever, the idea of et is quite similar. We need a leaf node and a binary non-leaf node for expressing
0
2019
by: Bonj | last post by:
hello this is a purely algorithmical question but if i have posted to an irrelevant group, apologies. can anyone point me at some good tutorials or info about the steps involved in creating a high-end generic binary tree (or, ternary search tree). The basic method I've got at the moment is having a resource file containing a series of data structures (which represent strings), specifically organised such that a test string can be matched...
8
6013
by: Chua Wen Ching | last post by:
Hi there. I was wondering is there any C# A* Pathfinding source code! I try to find and the best place is planetsourcecode vb.net A* Pathfinding... but vb.net syntax is too different if compare to C#... i am stuck here and there...
4
4937
by: Mitchel Haas | last post by:
Hello, Feeling a need for a generic tree container to supplement the available containers in the STL, I've created a generic tree container library (TCL). The library usage is very much like the containers in the STL, including iterator usage. Info on the library can be found here.. http://www.visuallandlord.com/developers_corner/open_source/tree_container_library/overview.php The library and sample code can be downloaded from this...
0
13329
by: JosAH | last post by:
Greetings, I was asked to write a Tip Of the Week; so here goes: a lot of topics are started here in this forum (and a lot of other forums too) mentioning a problem about sorting data. Examples of two main problem scenarios are like this: 1) an array containing a first name and another array containing a last name and possibly a third array containing the age of a person; how to sort the
1
2567
by: Christopher | last post by:
I hate to start from scratch as the need for it isn't as great as the work it would take. But, it sure would be nice if I had some data structure that represented a generic tree. I heard using boost's graph library might be an option. Any resources on doing so to implement a tree around? Or any suggestions on an alternative?
15
2394
by: Lloyd Dupont | last post by:
Don't mistake generic type for what you would like them to be!! IFoo<Ahas nothing in common with IFoo<B>! They are completely different type create dynamically at runtime. What you ask is a bit akin to ask: "the System.Web.UI and System.Windows.Controls namespace both contains a Control class, could I use one in place of the other? common they have the same name!" If you want to use a method common to both you should do as Alun...
0
10651
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
10405
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
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
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
6893
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
5556
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
4342
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
3871
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
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.