Question: Four algorithms are given below, where n is the input size. Replace k, m and p with the values in Question 1. Analyze (calculate) the
Four algorithms are given below, where n is the input size. Replace k, m and p with the values in Question 1. Analyze (calculate) the worst case time complexity of the algorithms and give your results in (.).
ALG1(n)
for ik to n j=n;
while (j>1) j=j-m;
ALG2(n)
i=n; while(i>k)
i=i/m;
for j1 to i
print j;
ALG3(n)
if n
Question 5 (30p) Four algorithms are given below, where n is the input size. Replace k, m and p with the values in Question 1. Analyze calculate the worst case time complexity of the algorithms and give your results in 0(.). ALG1 (n) for it kto n jan; while (11) j-j-m; ALG2 (n) i=n; while(i>k) i=i/m; for 1 to i print j; ALG3 (n) if nak return 1; else return (ALG3 (n/p) +1); ALG4 (n) if nak return 1; else return (ALGA(n-p) +1); Question 1 (5p) Given that; k is the number of letters in your first name m is the number of letters in your surname pis one more than the last digit in your student id (if your id is 202111003, p is 4) Si is the first 3 letters of your first name with "EA" as suffix (For example, if your name is "HASAN", S, will be "HASEA") Sz is the first 3 letters of your surname with "AE" as prefix (For example, if your surname is "OGUL", Sz will be "AEOGU" Write the values of k, m, p, S, and S, k....m.... pa.... S, S2 = Please note that you will need these values in other questions
return 1;
else
return (ALG3(n/p)+1);
ALG4(n)
if n
return 1;
else
return (ALG4(n-p)+1);
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
