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?
- A. 175
- B. 8
- C. 9
- 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.
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 tree has the vertices E, F, G, I, K, N, Y and the edges G–F, G–N, F–E, N–K, K–Y, K–I. A centroid is a vertex whose removal leaves no…
- An undirected graph on 7 vertices has the edges J–P, J–O, J–U, P–O, P–B, P–U, O–S, O–A, O–U, A–U. How many simple paths (no repeated…
- Grid with 4 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G.. G.G. .... .... Each step, which is a…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→E (6), S→A (2), S→C (2), S→T (6), E→T (2), D→A…
- A directed graph has the vertices D, E, H, I, K, N, O and the arcs N→E, N→D, K→N, K→O, E→O, I→N, I→E, H→K, O→N. How many strongly…
- A tree has the vertices A, C, M, R, V, Y, Z and the edges C–M, M–A, C–R, A–Y, A–V, R–Z. A set D dominates the tree if every vertex is in D…