How to check an algorithm for correctness?