Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please provide answers to all questions... For questions that need codes: Provide coding that can be copied and pasted to MATLAB. I am having extreme

image text in transcribedimage text in transcribedPlease provide answers to all questions... For questions that need codes: Provide coding that can be copied and pasted to MATLAB. I am having extreme difficulty with this homework, provide explanations if possible as well .

Consider the pseudocode for computing an array of prime numbers less than or equal to n. INPUT 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.) n - positive integer for k - 2....n for j = 2, 3, k-1 if remainder(k) = 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 thenii1 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 Ifn 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 primelist slow.m created in class (and available via Blackboard). 2. (20 points) Write a pseudocode incorporating these changes with input n and output p E NT(), which is an array of all prime numbers less than or equal to n 3. (20 points) Create a Matlab function, titled prime.list that implements your pseu- 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 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.) n - positive integer for k - 2....n for j = 2, 3, k-1 if remainder(k) = 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 thenii1 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 Ifn 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 primelist slow.m created in class (and available via Blackboard). 2. (20 points) Write a pseudocode incorporating these changes with input n and output p E NT(), which is an array of all prime numbers less than or equal to n 3. (20 points) Create a Matlab function, titled prime.list that implements your pseu- 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions