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?
- A. 7
- B. 9
- C. 174
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {4, 5, 6} and s ≤ the pile size. The player who…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {2, 3, 5} and s ≤ the pile size. The player who…
- A directed acyclic graph has the vertices A, E, F, J, S, U and the arcs A→E, A→S, A→F, E→J, E→S, E→F, E→U, J→U, F→U. Two players…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {3, 4, 6} and s ≤ the pile size. The player who…
- A tree has the vertices C, F, G, I, N, R, S and the edges R–G, R–S, S–I, I–C, C–F, R–N. A set D dominates the tree if every vertex is in D…
- A tree has the vertices B, C, F, K, M, N, Q, R, X, Z and the edges C–X, X–Z, X–M, M–K, C–B, Z–R, B–Q, M–N, N–F. What is the minimum number…