Question: 1 . boolean isPrime ( int n ) { / / tests if n is a prime number 2 / / Input: a positive integer
boolean isPrimeint n tests if n is a prime number
Input: a positive integer n
Output: returns true if n is a prime number, false otherwise
for int x ; xx n; x
if n x find that x divides n
return false;
return true; found no divisor of n
Note: when giving the bigOh give the nearest possible upper limit
possible. For example, if you can prove that fn is On and fn is On
choose the nearest upper bound, ie that fn is On
a pts Give a bigOh for Tn the worstcase execution time of this algorithm for an integer input n
algorithm for an integer input n Explain how you obtained this worstcase
case.
b pts Give a bigOh for Bn the best execution time for this algorithm
for an integer input of input n Explain the type of inputs not just one
but an infinite sequence of inputs that will give this best case.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
