in reply to Re: Sort mechanics problems with objects and potentially contradicting comparisons (would cause infinite loop)
in thread Sort mechanics problems with objects and potentially contradicting comparisons (would cause infinite loop)

You haven't realised that any traversal would be infinite for the failing cases for the same reasons. Repeat visits to a node in the structure tell you nothing about whether the traversal is finite. And counting those is not really a direct approach. A sort is a kind of traversal too.

One world, one people

  • Comment on Re^2: Sort mechanics problems with objects and potentially contradicting comparisons (would cause infinite loop)

Replies are listed 'Best First'.
Re^3: Sort mechanics problems with objects and potentially contradicting comparisons (would cause infinite loop)
by Anonymous Monk on Jun 02, 2016 at 16:45 UTC

    This problem is known as cycle detection, and there are a number of different solutions, depending on your requirements.

    Repeat visits to a node in the structure tell you nothing about whether the traversal is finite.

    I'm not sure what you mean by that. Repeat visits to a node tell you that you're in a cycle, and you'll keep going around forever unless you break out (as Floyd's code does).

    Most sort algorithms won't loop infinitely if the comparison function is inconsistent. They'll just return the list in a non-meaningful order.

      The problem with that is that all you do is move the infinite loop somewhere else rather than predict it. Or if the sort algorithm terminates instead, it will ignore dependencies.

      One world, one people