Question: Please help with all questions and bonus. provide codes that can be copied and pasted to matlab Consider the pseudocode for computing an array of

Please help with all questions and bonus. provide codes that can becopied and pasted to matlab Consider the pseudocode for computing an arrayPlease help with all questions and bonus. provide codes that can be copied and pasted to matlab

Consider the pseudocode for computing an array of prime numbers less than or equal to n. INPUT n - positive integer OUTPUT p is an array of prime numbers less than or equal to n. (T(n) is the number of prime numbers less than or equal to n.) for k = 2 n for j = 2, 3, . . . k-1 if remainder(k/j) 0 then k is composite, stop loop and go to next k value end if statement end for loop If inner loop cycled all the way through then i = i + 1 then Pi k end if statement end for loop The algorithm can be summarized in this way. Consider whether each integer from 2 to n is prime by dividing it by all integers greater than 1 and less than the number being considered If one of those lesser numbers divides evenly into our candidate prime, then it's composite. Otherwise it is prime and we add that candidate number to the list. This algorithm is implemented in the code prime.list.slow.m. As the code name sug- gests, we can accelerate the speed of the code. That is the subject of this homework Theorem 1 Ifn is not divisible by any prime number less than n, then n is a prime number. Theorem 2 If n is not divisible by any integer between two and vn, then n is prime. 1. (20 points) Explain how the the two theorems above can be used to accelerate the code 2. (20 points) Write a pseudocode incorporating these changes with input n and output 3. (20 points) Create a Matlab function, titled prime.list that implements your pseu- prime.list.slow.m created in class (and available via Blackboard) p E NT(n), which is an array of all prime numbers less than or equal to n. docode above. Your function should have the following input and output: Input n - positive integer Output p an array of prime number less than or equal to n The first line of your code should therefore read: function p-prime-list (n). Consider the pseudocode for computing an array of prime numbers less than or equal to n. INPUT n - positive integer OUTPUT p is an array of prime numbers less than or equal to n. (T(n) is the number of prime numbers less than or equal to n.) for k = 2 n for j = 2, 3, . . . k-1 if remainder(k/j) 0 then k is composite, stop loop and go to next k value end if statement end for loop If inner loop cycled all the way through then i = i + 1 then Pi k end if statement end for loop The algorithm can be summarized in this way. Consider whether each integer from 2 to n is prime by dividing it by all integers greater than 1 and less than the number being considered If one of those lesser numbers divides evenly into our candidate prime, then it's composite. Otherwise it is prime and we add that candidate number to the list. This algorithm is implemented in the code prime.list.slow.m. As the code name sug- gests, we can accelerate the speed of the code. That is the subject of this homework Theorem 1 Ifn is not divisible by any prime number less than n, then n is a prime number. Theorem 2 If n is not divisible by any integer between two and vn, then n is prime. 1. (20 points) Explain how the the two theorems above can be used to accelerate the code 2. (20 points) Write a pseudocode incorporating these changes with input n and output 3. (20 points) Create a Matlab function, titled prime.list that implements your pseu- prime.list.slow.m created in class (and available via Blackboard) p E NT(n), which is an array of all prime numbers less than or equal to n. docode above. Your function should have the following input and output: Input n - positive integer Output p an array of prime number less than or equal to n The first line of your code should therefore read: function p-prime-list (n)

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!