Question
Suppose you want to move from 0 to 100 on the number line. In each step, you either move right by a unit distance or you take a shortcut. A shortcut is simply a pre-specified pair of integers with . Given a shortcut if you are at position on the number line, you may directly move to . Suppose denotes the smallest number of steps needed to move from to 100. Suppose further that there is at most 1 shortcut involving any number, and in particular from 9 there is a shortcut to 15. Let and be such that . Then the value of the product is _____.
Official answer and solution
- Official answer
- 150
- From
- Official GATE 2014 answer key
Solution
Write the Bellman-Ford / shortest-path dynamic programming recurrence for moving on the number line from 9.
-
Let denote the minimum number of steps to reach 100 starting from position .
-
From position , only two valid moves exist in one step:
- Option 1 (regular unit step): Move right by distance 1, reaching position . The remaining steps from this choice will be , giving a total of steps.
- Option 2 (shortcut): The problem states that from 9 there is a shortcut to 15. Taking this shortcut reaches position 15 in 1 step. The remaining steps will be , giving a total of steps.
-
By the principle of optimality (dynamic programming):
-
Comparing this with the given equation :
-
The product of and is:
150
Confusing the shortcut destination with the difference (15 - 9 = 6).
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2014 Computer Science and Information Technology (CS) Session 3
- Question
- 47 of 65, printed as CS Q.37
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.