I would like to understand why the following naive primality test algorithm is not polynomial.
IsPrime (n: an integer)
Begin
For i=2 to n-1 do
If (n % i == 0) then
return (no)
EndIf
EndFor
return (yes)
End
This algorithm is said to be exponential in the size of the input n. Why is it true? And why the following sorting test algorithm is said polynomial and not exponential?
IsSorted (T[n]: an array of n integer)
Begin
For i = 1 to n-1 do
If (T[i] > T[i+1]) then
return (no)
EndIf
EndFor
return (yes)
End