473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 3507

"Nevyn" <ne***********@hotmail.com> wrote in message
news:pa****************************@hotmail.com...
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
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...
18
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...
4
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...
0
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...
8
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...
4
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...
0
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. ...
1
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...
15
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...

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.