Forgive me if my answer is incorrect in terms of syntax, but my Algorithm course was a long time ago (and not in English).
If I understand your problem correctly, you want to find out what maximum number you can count, starting with node A and reaching node B without "re-checking" your steps. If so, I would suggest that your schedule is acyclic (a cyclic version will appear later).
First of all, the upper limit is the number of edges. As I see it: take one node, create a tree where the node is in the root, and each subsequent node that you can reach is at the next level. The height of the tree you are building is the diameter, and the leaves are the nodes that are at that distance. If this distance = number of edges, you are done. If not, select another node and repeat.
I think this is like building a breadth-first search. Without knowing more about the graph, you could use some heuristics to see which tree orientation (i.e. which node should be selected first) would be better, but this is another topic.
Regarding the cyclical nature of the chart, as others have indicated, this can lead to endless cycles. A way to get rid of them may be to “exclude” the nodes that belong to the cycle, and add the longest path between them as the value that you get by entering the cycle and exiting it, touch each node only once.
Now, as I said, this method can easily be the same as for the whole pair shortest path. Worst of all, the complexity of the case, of course, is the same and cannot be otherwise.
lorenzog Jan 6 '10 at 19:22 2010-01-06 19:22
source share