Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

Starting from the integer 3, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative integers. What is the minimum number of operations needed to reach exactly 177?

  1. A. 7
  2. B. 9
  3. C. 174
  4. D. 8

Correct answer: D. 8

A BFS over the integers gives 8 operations. Peeling back from 177 with halving-when-even gives 9; using only +1 and doubling (no subtraction) needs 9.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic