Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following algorithm for testing if a given positive integer n is a

ID: 669786 • Letter: C

Question

Consider the following algorithm for testing if a given positive integer n is a prime number. Argue that this algorithm is correct - specifically, that it is sufficient to only consider candidate factors of n in the range 2 through n. What is the worst case running time of this algorithm as a function of n? Let s be the size of the input to this algorithm. Rewrite the worst case running time of this algorithm as a function of s. Is this a polynomial-time algorithm or an exponential-time algorithm? Implement the above algorithm in your favorite high-level language (e.g., Java, C++, Python, Scala, etc.). This should take no more 10-15 lines of code. Try to use your program to determine if 758500183202087890352073067 is a prime. As an answer to this problem, tell us if this number is a prime, but more importantly, tell us how long your program took to determine if the input was a prime. For this part of the question, it is okay to say something like "I ran my program overnight and it did not complete and so I don't know if the input is a prime."

Explanation / Answer

Consider the following algorithm for testing if a given positive integer n is a

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote