You are on page 1of 6

ESO207 - Assignment 1

Tanush Kumar (201043)


Kartikeya Raghuvanshi (200494)
—---------------------------------------------------------------------------------------------------------------------

Ques 1) The implementation of each algorithm is supposed to work for each possible value
of n upto 1018. However, it will turn out that some of these algorithms will start taking too
much time as n increases. In order to observe this on your own, for each algorithm, you
have to experimentally determine the largest possible value of n for which the
corresponding implementation gives the output within the time limit (in seconds) from the
set {0.001, 0.1, 1, 5, 60, 600}. You need to fill up the table given below with these values. If
value of n exceeds 1018 for a specific time interval from the set, write > 1018 in the
corresponding entry in the table.

Ans 1)

Time → 0.001s 0.1s 1s 5s 60s 600s

RFib 25 35 41 44 49 54

IFib 80,000 11,000,000 110,000,000 550,000,000 6,400,000,000 64,000,000,000

CleverFib 265,000 211,200,000 2120,000,000 2610,000,000 27,200,000,000 270,000,000,000

—--------------------------------------------------------------------------------------
-------------------------------
Ques 2) Plot the following graphs:
Ans 2 i) Log2(Time taken by RFib) as a function of n.

Ans 2 ii) Time taken by IFib as a function of n.


Ans 2 iii) Time taken by CleverFib as a function of log2(n)

Ques 2a) Provide precise and concise justification for the shapes of the graphs you obtain.

Ans 2a) It is because of the time complexities of the different algorithm. The time
complexity of RFib is proportional to 2n, so the log of time taken is proportional to n and
hence we get a straight line graph. Similarly, IFib is proportional to n and Clever is
proportional to log(n). Thus we get a straight line in all cases.

Ques 2b) If a graph is a line, what is the value of its slope ? If each graph is a line, can you
provide an explanation for the difference in their slopes ?

Ans 2b)
For RFib the log of time complexity will be greater than n/2 so the value of the slope will be
greater than 0.5 (form the grap we can infer that the value will be close to 0.6).
For IFib the time complexity is ≈3n so the slope of the graph will be 3.
For CleverFib, the slope is about 10^(-8) as visible from the graph.

Ques 2c) In each call of CleverFib, the number of instructions executed (excluding the
recursive call invoked) are significantly more than RFib. Moreover, CleverFib involved
multiplication operation whereas the other two algorithms involved only addition operation.
We know that multiplying a pair of numbers takes more time than adding a pair of numbers
on a computer.

Ques 2c i) Did these facts influence the running time of CleverFib?


Ans 2c i) Yes, since there are more operations involved, the running time of CleverFib for
smaller numbers will be more.

Ques 2c ii) Did these facts affect the relative speed of CleverFib compared to the other 2
algorithms ? If not, then state the reason.

Ans 2c ii) For bigger numbers, the relative speed will not be affected by the number of
instructions per iteration because the relative speed is primarily determined by the number
of iterations. The number of instructions per iteration is much lower and is therefore
dominated by the number of iterations for large numbers. Hence, the relative speed of
CleverFib is not affected when compared to the other algorithms.

—--------------------------------------------------------------------------------------
-------------------------------
Ques 3) Based on the observations and inferences from 1 and 2 above, how accurate did you
find the RAM model of computation in measuring the running time of an algorithm ? How
accurate did you find the RAM models of computation in comparing the efficiency of a pair
of algorithms ?

Ans 3) No (can’t compute exact time)


Yes (accurate to compare algorithms)

—--------------------------------------------------------------------------------------
-------------------------------
Ques 4) Did this assignment achieve its objective stated on the 2nd page ? To answer this
question, please choose one of the following options honestly, sincerely, and purely based
on your own experience. Also provide a brief justification if possible.

(a) This assignment was like any other assignment we do routinely. I did not find any thing
special in it.

(b) This assignment does not seem to achieve the objective stated on the 2nd page.

(c) This assignment was an eye-opener for me. I found it immensely useful.

You are welcome to share any experience related to this assignment if you wish.

Ans 4) C

—--------------------------------------------------------------------------------------
-------------------------------

You might also like