Skip to content
Official PYQ · 2014

GATE CS 2014 Set 3 Q37 — Algorithm Design: Dynamic Programming

Explain with AI

Suppose you want to move from 00 to 100100 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 i, j with i<ji,\:j \:\text{with}\: i <j. Given a shortcut (i,j)(i,j), if you are at position ii on the number line, you may directly move to jj. Suppose T(k)T(k) denotes the smallest number of steps needed to move from kk to 100100. Suppose further that there is at most 11 shortcut involving any number, and in particular, from 99 there is a shortcut to 1515. Let yy and zz be such that T(9)=1+min⁡(T(y),T(z))T(9) = 1 + \min(T(y),T(z)). Then the value of the product yzyz is _____.

View worked solution

Answer: 150

To find the minimum number of steps T(k)T(k) to reach 100100 from any position kk, we analyze the choices available at position kk.

At any position kk, we can always make a standard move of 11 unit to the right, reaching k+1k+1. Additionally, if there is a shortcut starting at kk to some destination jj, we can also choose to jump directly to jj.

For k=9k = 9:

  1. Standard move: Move 11 unit right to reach 1010. The remaining steps needed would be T(10)T(10).
  2. Shortcut move: We are given that there is a shortcut from 99 to 1515. Taking this shortcut leads to position 1515. The remaining steps needed would be T(15)T(15).

Since we want to minimize the number of steps, the optimal choice from 99 is given by the recurrence:

T(9)=1+min⁡(T(10),T(15))T(9) = 1 + \min\big(T(10), T(15)\big)

Comparing this with the given equation:

T(9)=1+min⁡(T(y),T(z))T(9) = 1 + \min\big(T(y), T(z)\big)

We identify that the set of values for {y,z}\{y, z\} is {10,15}\{10, 15\}.

Thus, the product yzyz is:

yz=10×15=150yz = 10 \times 15 = 150

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Algorithm Design: Dynamic Programming questions