Non-deterministic algorithm