I recently completed a coursework on PRIMES and time complexity, and I got marked down for something which I think I got right, I wanted to ask here to make sure. Here is the problem and I will talk through my answer and what the marker said:
The problem PRIMES is defined as follows:
PRIMES takes an integer, n and returns YES if n is prime, and NO if n is not prime.
Show that PRIMES is in coNPTIME.
So my thought process was that I would prove that the complement of PRIMES is in NPTIME, I gave the complement of PRIMES as NOT-PRIMES, defined as follows:
NOT-PRIMES takes an integer, n and returns YES if n is not prime, and NO if n is prime.
Then I proved that NOT-PRIMES was in NPTIME by giving an algorithm which runs successfully in non-deterministic polynomial time:
a := 1
b := 1
while a * b != n {
a := a random number where 1 < a < n
b := a random number where 1 < b < n }
return YES
So this proves that NOT-PRIMES is in NPTIME, hence PRIMES is in coNPTIME (This is just an informal version, I used more formal language in my actual answer).
So the question was marked out of 2, and I received 1 mark. The marker drew a red circle around my algorithm and said 'this might not terminate!'.
While he is not wrong, the algorithm might not terminate, I fail to see how this affects the validity of my proof.
It was my understanding that in order for a problem to be in NPTIME, there must be a correct algorithm which has at least one successful run on a non-deterministic Turing machine.
My algorithm clearly has at least one successful run on all non-prime inputs, as if a and b are immediately guessed as the factors of n then it will return 'YES' in polynomial time.
My algorithm is correct, if n is prime, then it can never return 'YES' incorrectly.
The algorithm would not, however, terminate on a prime input, but it was my understanding that this did not matter, as it was a 'NO' answer anyway, and the only requirement for membership in NPTIME is that there is a successful 'YES' run in polynomial time.
Was I marked down incorrectly? If I wasn't, could someone please explain what I misunderstood or link me to a resource which could explain?
Thanks a lot, Michael