Question: is to analyse your friend's algorithm: ( i ) Suppose the next turn is the ith turn. What is the time complexity of a step

is to analyse your friend's algorithm:
(i) Suppose the next turn is the ith turn. What is the time complexity of a step which does not find an ideal turn?
(ii) Suppose the next turn is the ith turn. What is the time complexity of a step which does find an ideal turn?
(iii) What is the maximum number of ideal turns there can be in terms of n and m?
(iv) Therefore, what is the time complexity of the entire algorithm?
This is an example of amortisation, where a single operation may be slow but the sequence of operations is guaranteed to be fast.
Hint: The time complexity should account for setting up array f, as well as the time spent at each ideal turn and at each not ideal turn.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!