Consider a process of incrementing a binary n-bit counter. An increment causes some bits to be flipped: Some 0s are changed to 1s, and some 1s to 0s. In the best case, counting involves only one bit switch; for example, when 000 is changed to 001, sometimes all the bits are changed, as when incrementing 011 to 100.
Number | Flipped | Bits |
000 |
|
|
001 | 1 |
|
010 | 2 |
|
011 | 1 |
|
100 | 3 |
|
101 | 1 |
|
110 | 2 |
|
111 | 1 |
|
Using worst case assessment, we may conclude that the cost of executing m = 2n – 1 increments is O(mn). Use amortized analysis to show that the cost of executing m increments is O(m).
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.