Data Structures & AlgorithmsModerateGATE CS · ICPC regional

Starting from the integer 6, 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 181?

  1. A. 175
  2. B. 8
  3. C. 9
  4. D. 11

Correct answer: B. 8

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic