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?
- A. 1000
- B. 2000
- C. 1994
- 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
- Unit-time jobs with (deadline, profit): (2,100), (1,19), (2,27), (1,25), (3,15), (3,90), (4,60), (5,10). Each job takes one slot and must…
- Keys 22, 33, 44, 12, 23, 34, 45, 1 are inserted in this order into a table of size 11 using h(k) = k mod 11 with linear probing. Counting…
- A DAG on vertices 0..5 has edges 0→2, 1→2, 1→3, 2→4, 3→4, 3→5, 4→5. How many distinct topological orderings does it have?
- A binary search (loop while low ≤ high, mid = ⌊(low+high)/2⌋) runs on a sorted array of 1000 elements. The maximum number of loop…
- Keys 1..7 are inserted into an initially empty BST (no balancing) in some order. For how many of the 7! insertion orders does the…
- Keys 1..8 are inserted into an empty BST in each of the 8! possible orders. In how many orders is the resulting tree a single path (height…