Link to home
Start Free TrialLog in
Avatar of psm8780
psm8780

asked on

Searching a tree

Hi,
If I am given a tree how can I find a path from each node to everyother node?
Thanx,
Avatar of psm8780
psm8780

ASKER

I need answer as soon as possible, plz....
I'm not quite sure of your question.....

Usually you start at the top of a tree.

Are you saying you start at a leaf node, and you have to traverse every possible node in the tree?  (in which case you'll need a pointer "upwards" as well.  Are you looking for shortest distance???

Obviously, trees work with recursive algorithms.  Could you give some more details.

Cheers,

keenez
BTW .... since this sounds like homework ... we can only give you some pointers but we won't do it for you.

Keenez

And we want 10 points of your grade to come to us.

What type of tree is it?
ASKER CERTIFIED SOLUTION
Avatar of tox
tox

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
tox, if you had read what keenez said, you'd know you're not supposed to completely solve homework problems in here.
Let me assume now that you know how to find the path from one node to another node. What you need to find EVERY path is to put a complete traversal result to a list and duplicate this list. Say you've got a preorder list of a,b,c,d , so the second list is also a,b,c,d. The number of paths here are 4*(4-1)=12. Parse the enumerated p2p parameters to the node-to-node finder, and there you go.

To Linzer and Keenez:
  Hi, thanks for pointing it out that no homework solutions should be provided here. I'll pay more attention to such things from now on.

 
Avatar of psm8780

ASKER

Hey, this was not exactly a homework. Actually I am supposed to be working on this project where I have to find a link carrying maximum traffic in a telecom network. For this I needed a faster solution than DFS to traverse a tree; since my algorithm is getting into cubic running time. Anyway, I did not ask you to do my homework. I just needed an algorithm faster that DFS. But thanx neway....I am accepting tox's answer though it does not solve my problem!!! The reason is I found out from my tacher that its ok to have cubic running time!!!!