Question: (VI). Given Algorithm 1, answer the following questions. 1: procedure FINDALLPR?MES(n) 3: fori 3, n do 5: b n is an integer and n >2

(VI). Given Algorithm 1, answer the following questions. 1: procedure FINDALLPR?MES(n) 3: fori 3, n do 5: b n is an integer and n >2 Initialize S as a set with only one element 2 p Scan all integers from 3 to n D R is the maximal possible divisor 2: S 12 flag true for j 2, R do 6: b Go through all possible divisors if j divides i then flag false break from the inner loop 9: 10 end if end for if flag true then end if 12: 13: 15: end for 16. return S 17: end procedure b Return a list of all primes (1) For the outer loop (line 3 to 15), how many iterations will be executed? (2) In line 4, why we can set R-lv (3) Given a specific i, what is the maximal number of iterations that the inner loop (line 6 to 11) will be executed? (4) If we use division as the operation, what is the time complexity using Big-O notation? (5) Explain your answer for the previous question. ICOM 4075 / aica?75: Pred Kejie Lu
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
