Answered step by step
Verified Expert Solution
Question
1 Approved Answer
. Q2. [20 marks] A prime number (or a prime) is a natural number greater than 1 that doesn't have other factors but 1 and
. Q2. [20 marks] A prime number (or a prime) is a natural number greater than 1 that doesn't have other factors but 1 and itself. Given a parameter n, detecting all prime numbers in [2,n] is a fundamental problem. In the following, we will show you two different algorithms implemented by C language. Analyze the time complexity of each one with big-O notation. void algo(int n, int isPrime[]) The array isPrime contains the result. isPrime[i] = 0 : i is not a prime; isPrime[i] = 1 : i is a prime. - Algorithm1 1 2 int i, 3 4 void algo1 (int n, int isPrime[]){ j; for (i =2; i 1), 2), 3j, 4j, are not prime numbers. 1 2 3 = 4 void algo2 (int n, int isPrime []) { int i, j; for (i =2; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started