logoalt Hacker News

amilioslast Thursday at 2:37 AM3 repliesview on HN

Am I missing something? If the algorithm is interrupted, the list will not be sorted. How exactly does it fit the criteria of an anytime algo?


Replies

addaonlast Thursday at 3:03 AM

An anytime algorithm monotonically improves some evaluation metric. For a sort, the evaluation metric is usually the number of inversions in the list. At completion, there will be zero inversions. If at time 0 there are N inversions, then at time 0 < t < completion time there will be ≤ N inversions; that is, the list is "more sorted" than it was before. As the various examples about games and animation elsewhere in the comments show, this can be interpreted as "somewhat smoothly moving towards sorted over time," which is an (occasionally) ((rarely)) useful property.

Pannoniaelast Thursday at 2:42 AM

Okay, but it gives you a mostly good answer! Unlike many other sorts where if you interrupt it before the last step, you get total nonsense.

It's basically asymptotically approacting the correct (sorted) list instead of shuffling the list in weird ways until it's all magically correct in the end.

show 1 reply