GATE Computer ScienceHardGATE CSE

A binary counter starts at 0 and is incremented 1000 times. The cost of an increment is the number of bits that flip. What is the total cost?

  1. A. 1000
  2. B. 2000
  3. C. 1994
  4. D. 1998

Correct answer: C. 1994

Bit i flips ⌊1000/2^i⌋ times: 1000+500+250+125+62+31+15+7+3+1 = 1994.

More Algorithms questions

Exams that ask this topic