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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started