Question: Problem 2.(10 points) We are interested in measuring the time complexity ofexecuting a sequence ofninvocations of the following function with the arrayA initially containing all

Problem 2.(10 points) We are interested in measuring the time complexity ofexecuting a sequence ofninvocations of the following function with the arrayA initially containing all 0s.Function increment(A)Input:A[0..m-1] is an array of 0-1 bits representing a binary counterOutput:A after its value incremented by 1 modulo 2mi0whilei < mandA[i] = 1doA[i]0ii+ 1endifi < mthenA[i]1end(a) Note the time complexity of the function is proportional to number of itera-tions of the while loop and can beO(m) in the worst case. Thus concludingthat the sequence ofninvocations takesO(mn) time is incorrect as it isa loose bound. We can use amortized complexity analysis to improve thebound. Using accounting method show that the amortized complexity ofa single invocation in a sequence ofninvocations is O(1). [Hint : Assumecost of a function is measured by number of bit flips(0 to 1 and 1 to 0)required. Argue that the amortized cost is 2 units per invocation](b) What potential function will you use for the amortized analysis ? Derivethe amortized time complexity using this potential function.

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 Databases Questions!