Question: Please be descriptive in your answer and explain as much as you can. Thanks! Also please provide a complete answer Consider the following algorithm that

Please be descriptive in your answer and explain as much as you can. Thanks! Also please provide a complete answer

Consider the following algorithm that gets an integer m (an n-bit integer) as input and determines whether m is a prime or not.

Input: m

x = sqrt(m);

for(int i = 2; i<=x+1; i++)

if (m % i == 0)

return false;

return true;

What is the best-case and worst-case run times of the above algorithm (in big-oh nota- tion). On which types of inputs does the best-case run-time happen and on which types of inputs does the worst-case run time happen? Note that you should express the run time in terms of the size of the input (what is the run time if the algorithms get an n-bit integer as input?). You may assume that the time taken to compute the square-root function in the algorithm is O(1).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!