type a = b
type b = a
If a program has a structure like this with cyclic dependencies, then the compiler must be aware of this and break. (At least, I can imagine a situation where this could be a desired attribute.)
type a = b
type b = a
If a program has a structure like this with cyclic dependencies, then the compiler must be aware of this and break. (At least, I can imagine a situation where this could be a desired attribute.)
http://stackoverflow.com/questions/16436165/detecting-cycles...
This is at least very easy to reason about. However, if you are still right my thought process is just very wrong.
A linked list is a particular type of DAG (or at least DG). The relevant distinction between linked list and the general case is that a linked list restricts nodes to (zero or) one outbound edge. This is relevant to the problem at hand, because you only have one tortoise and one hare and so they can only follow one path.
That doesn't get around the original objection, though, which is that the restriction has to be exploited to get the algorithm in question, and thus the algorithm cannot be applied to the general case of graphs.
Having said that, certainly the ability to make use of restrictions provided by your domain is hugely valuable, and this should serve as a relatively familiar case.
But not in O(1) space, right?
I can imagine representing the graph as a list of paths, in which case the tortoise-and-hare algorithm is O(1) space, though the graph itself would be (potentially much) larger. Virtually every other operation on such a graph would take a performance hit, too.
There may be other factors I haven't thought of, but you're right that the generalized algorithm could not be as space-efficient as the special algorithm.
It's worth noting, though, that the original question poised in the article did not place an O(1) restriction on space.
For sure.