Nondeterministic algorithm