How to tell if an algorithm terminates?