GATE Overflow - Recent questions tagged dynamic-programming
http://gateoverflow.in/tag/dynamic-programming
Powered by Question2AnswerWhat is the general idea to approach to problems in Dynamic Programming ?
http://gateoverflow.in/101336/what-the-general-idea-approach-problems-dynamic-programming
<p>Could someone tell me What is the general idea to approach to problems in Dynamic Programming ?
<br>
<br>
ie. Given a problem How do I start my thinking :P , Im not getting a clue to deal with DP problems . Making Recursive Equations etc .
<br>
<br>
Is DP approach is suitable for any problems ?
<br>
<br>
---------------------------------------------------------------------------------------------------------------------------------------------------</p>
<p>Example Problem
<br>
<br>
Min-Coin Change is the problem of using the minimum number of coins to make change for a particular amount of cents, <img alt="n" src="http://www.algorithmist.com/images/math/7/b/8/7b8b965ad4bca0e41ab51de7b31363a1.png">, using a given set of denominations <img alt="d_{1}\ldots d_{m}" src="http://www.algorithmist.com/images/math/7/f/7/7f7cc82f1372dcfe050b2301fbc188f9.png">.</p>
<p>Given the denominations 1, 5, 10, 20, 25, and wish to make change for 40 cents, the greedy algorithm would give us 25, 10, 5, but the best solution only requires 2 coins - 2 of the 20 cent coins</p>Algorithmshttp://gateoverflow.in/101336/what-the-general-idea-approach-problems-dynamic-programmingFri, 06 Jan 2017 05:13:45 +0000Made Easy Test Series
http://gateoverflow.in/100103/made-easy-test-series
<p><img alt="" src="http://gateoverflow.in/?qa=blob&qa_blobid=16494035913491667731"></p>Algorithmshttp://gateoverflow.in/100103/made-easy-test-seriesTue, 03 Jan 2017 15:10:18 +0000virtual gate
http://gateoverflow.in/98211/virtual-gate
<p><img alt="" src="http://gateoverflow.in/?qa=blob&qa_blobid=17764619701595438412"></p>Algorithmshttp://gateoverflow.in/98211/virtual-gateThu, 29 Dec 2016 18:44:58 +0000Find shortest path
http://gateoverflow.in/86958/find-shortest-path
<p><img alt="" height="400" src="http://gateoverflow.in/?qa=blob&qa_blobid=12914640239353443282" width="1101"></p>Algorithmshttp://gateoverflow.in/86958/find-shortest-pathSun, 27 Nov 2016 06:23:14 +0000Divide and conquer+Dynamic
http://gateoverflow.in/72538/divide-and-conquer-dynamic
<p><img alt="Loading Question" src="https://d2190hpfa85jkd.cloudfront.net/q/b447cbf84ec3a8edd819eeb39fc6523f.jpg"></p>Algorithmshttp://gateoverflow.in/72538/divide-and-conquer-dynamicSat, 08 Oct 2016 11:39:29 +0000Recurrence relation and probability
http://gateoverflow.in/64328/recurrence-relation-and-probability
<p>N rooms are there and they are numbered from 1 to N.</p>
<p>A person P is in charge of room allocation and allocates these rooms inthe following way: </p>
<ul>
<li>Each query ask for two consecutive rooms.</li>
<li>P selects two consecutive rooms out of the vacant rooms and serves the query. Once allocated those two rooms can not be reallocated. Example : if 2nd and 3rd rooms are vacant, P can consider to select them. If 4th,5th and 7th rooms are vacant, (5,7) can not be considered [ <em>these two can not be considered as allocatable ( because these two(5,7) are not consecutive) </em>] but (4,5) can be considered to be allocatable. <strong>Out of all allocatable vacant rooms <em>at present</em></strong> , P selects any two consecutive randomly (randomly uniform).</li>
<li>Queries are coming continuously and P is serving them.</li>
<li>At some point of time, all allocatable rooms are exhausted. At that time further queries are not processed. Process STOPPED.</li>
</ul>
<p>K is a positive integer $\leq$ N. What is the reccurece relation for the probability of Kth room being filled up after the room allocation process has been stopped.</p>
<p>one example :</p>
<p>If initially 4 rooms are given [1,2,3,4].</p>
<p>First query : assume P selects (2,3)</p>
<p>Seconds query onwards can not be processed. because although 1,4 are vacant, these rooms are not consecutive.</p>http://gateoverflow.in/64328/recurrence-relation-and-probabilityMon, 22 Aug 2016 18:53:56 +0000UGCNET-Dec2013-III-37
http://gateoverflow.in/60569/ugcnet-dec2013-iii-37
<p>The longest common subsequence of the sequences X=<A, B, C, B, D, A, B> and Y=<B, D, C, A, B, A> has length</p>
<ol style="list-style-type:upper-alpha">
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ol>Algorithmshttp://gateoverflow.in/60569/ugcnet-dec2013-iii-37Thu, 28 Jul 2016 02:54:45 +0000Maximum Continuous Sum in an Array
http://gateoverflow.in/55422/maximum-continuous-sum-in-an-array
Given an array of $n$ elements find the maximum continuous sum in it. For example consider the below array of $n=6$.<br />
<br />
23 4 -10 2 15 1<br />
<br />
Answer is 35.Algorithm Challengeshttp://gateoverflow.in/55422/maximum-continuous-sum-in-an-arraySun, 03 Jul 2016 06:30:23 +0000CMI2013-B-06b
http://gateoverflow.in/49177/cmi2013-b-06b
<p style="line-height: 20.8px;">Your final exams are over and you are catching up on watching sports on TV. You have a schedule of interesting matches coming up all over the world during the next week. You hate to start or stop watching a match midway, so your aim is to watch as many complete matches as possible during the week.
<br>
Suppose there are $n$ such matches scheduled during the coming week and you know the starting and finishing time for each match.</p>
<p>Develop an algorithm based on dynamic programming to compute the maximum number of complete matches you can watch next week. Analyze the worse-case complexity of your algorithm.</p>
Algorithmshttp://gateoverflow.in/49177/cmi2013-b-06bWed, 08 Jun 2016 07:17:00 +0000CMI2015-B-07
http://gateoverflow.in/47071/cmi2015-b-07
<p>There is a thin, long and hollow fibre with a virus in the centre. The virus occasionally becomes active and secretes some side products. The fibre is so thin that new side products secreted by the virus push the old products along the fibre towards its ends. The possible actions of the virus are as follows</p>
<ol style="list-style-type: lower-alpha;">
<li>Produce an acid molecule to its left and a base molecule to its right.</li>
<li>Produce a base molecule to its left and an acid molecule to its right.</li>
<li>Divide into two viruses, each of which continues to behave like its ancestor.</li>
<li>Die.</li>
</ol>
<p>You are given a sequence of acid and base molecules from one end of the fibre to the other end. Design an algorithm to check if a single virus could possibly have produced the given sequence. Use dynamic programming, checking smaller subsequences before checking bigger subsequences.</p>
<p> </p>
Algorithmshttp://gateoverflow.in/47071/cmi2015-b-07Fri, 27 May 2016 07:44:32 +0000CMI2014-B-05
http://gateoverflow.in/46985/cmi2014-b-05
At the end of its fifth successful season, the Siruseri Premier League is planning to give an award to the Most Improved Batsman over the five years. For this, an Improvement Index will be computed for each batsman. This is defined as the longest sequence of increasing scores by the batsman among all his scores over the five seasons. For example, if the scores for a batsman over the five seasons are (20, 23, 6, 34, 22, 52, 42, 67, 89, 5, 100), his Improvement Index is 7 based on the sequence (20, 23, 34, 52, 67, 89, 100). Describe an efficient algorithm based on dynamic programming to compute the Improvement Index for a batsman with an overall sequence of $n$ scores. Analyze the complexity of your algorithm.Algorithmshttp://gateoverflow.in/46985/cmi2014-b-05Fri, 27 May 2016 02:56:58 +0000What is the time complexity of Binary Knapsack?
http://gateoverflow.in/46580/what-is-the-time-complexity-of-binary-knapsack
<p>I was reading some of the notes (made easy and ACE) and noticed that some teacher have taught that time complexity for Binary Knapsack O(2^(n/2)). which can not be reduced further. but What I have seen <a rel="nofollow" href="http://www.geeksforgeeks.org/dynamic-programming-set-10-0-1-knapsack-problem/">here</a> that in worst case by using memoization we can reduce the time complexity upto O(n.W) where n is number of Object and W is capacity of knapsack.</p>
<p>What I am thinking that, Is it really Binary knapsack is NPC, Like Travelling Salesman problem because TSP tales O(n^2*2^n) times to calculate the tour by using dynamic method, which is efficient than o(n^n) of TSP brutforce techniques? Put some light, Am I missing something. Should I stop seeing those notes which people have posted over the internet. </p>
Algorithmshttp://gateoverflow.in/46580/what-is-the-time-complexity-of-binary-knapsackMon, 23 May 2016 06:18:35 +0000CMI2012-B-06
http://gateoverflow.in/46569/cmi2012-b-06
A certain string-processing language offers a primitive operation which splits a string into two pieces. Since this operation involves copying the original string, it takes n units of time for a string of length $n$, regardless of the location of the cut.<br />
Suppose, now, that you want to break a string into many pieces. The order in which the breaks are made can affect the total running time. For example, if you want to cut a 20-character string at positions 3 and 10, then making the first cut at position 3 incurs a total cost of 20 + 17 = 37, while doing position 10 first has a better cost of 20 + 10 = 30.<br />
Give a dynamic programming algorithm that, given the locations of m cuts in a string of length n, finds the minimum cost of breaking the string into m + 1 pieces. You may assume that all m locations are in the interior of the string so each split is non-trivial.Algorithmshttp://gateoverflow.in/46569/cmi2012-b-06Mon, 23 May 2016 03:51:51 +0000GATE2009-54
http://gateoverflow.in/43476/gate2009-54
<p>A sub-sequence of a given sequence is just the given sequence with some elements (possibly none or all) left out. We are given two sequences $X[m]$ and $Y[n]$ of lengths m and n, respectively with indexes of $X$ and $Y$ starting from $0$.</p>
<p>We wish to find the length of the longest common sub-sequence (LCS) of $X[m]$ and $Y[n]$ as $l(m, n)$, where an incomplete recursive definition for the function $I(i, j)$ to compute the length of the LCS of $X[m]$ and $Y[n]$ is given below:</p>
<p>l(i,j) = 0, if either i = 0 or j = 0
<br>
= expr1, if i,j > 0 and X[i-1] = Y[j-1]
<br>
= expr2, if i,j > 0 and X[i-1] ≠ Y[j-1]
<br>
The value of $l(i,j)$ could be obtained by dynamic programming based on the correct recursive definition of $l(i,j)$ of the form given above, using an array $L[M,N]$, where $M = m+1$ and $N = n+1$, such that $L[i, j] = l(i, j)$.</p>
<p>Which one of the following statements would be TRUE regarding the dynamic programming solution for the recursive definition of $l(i, j)$?</p>
<ol style="list-style-type: upper-alpha;">
<li>All elements of $L$ should be initialized to 0 for the values of $l(i, j)$ to be properly computed.</li>
<li>The values of $l(i, j)$ may be computed in a row major order or column major order of $L[M, N]$.</li>
<li>The values of $l(i, j)$ cannot be computed in either row major order or column major order of $L[M, N]$.</li>
<li>$L[p, q]$ needs to be computed before $L[r, s]$ if either $p<r$ or $q < s$.</li>
</ol>
Algorithmshttp://gateoverflow.in/43476/gate2009-54Sat, 23 Apr 2016 03:22:05 +0000In how many ways a rook can go from SouthEast to northwest corner of 8×8 chess board if travels only upwards or left?
http://gateoverflow.in/42390/southeast-northwest-corner-chess-board-travels-only-upwards
Combinatoryhttp://gateoverflow.in/42390/southeast-northwest-corner-chess-board-travels-only-upwardsSun, 10 Apr 2016 01:42:14 +0000GATE 2016-2-38
http://gateoverflow.in/39587/gate-2016-2-38
Let $A_{1}, A_{2}, A_{3}$ and $A_{4}$ be four matrices of dimensions $10 \times 5, 5 \times 20, 20 \times 10,$ and $10 \times 5$, respectively. The minimum number of scalar multiplications required to find the product $A_{1}A_{2}A_{3}A_{4}$ using the basic matrix multiplication method is _________.Algorithmshttp://gateoverflow.in/39587/gate-2016-2-38Fri, 12 Feb 2016 07:32:21 +0000GATE 2016-2-14
http://gateoverflow.in/39570/gate-2016-2-14
<p>The Floyd-Warshall algorithm for all-pair shortest paths computation is based on</p>
<ol style="list-style-type: upper-alpha;">
<li>Greedy paradigm.</li>
<li>Divide-and-conquer paradigm.</li>
<li>Dynamic Programming paradigm.</li>
<li>Neither Greedy nor Divide-and-Conquer nor Dynamic Programming paradigm.</li>
</ol>
<p> </p>
<p> </p>
Algorithmshttp://gateoverflow.in/39570/gate-2016-2-14Fri, 12 Feb 2016 06:46:38 +0000Final Analysis DIJIKSTRA ALGORITHM
http://gateoverflow.in/35239/final-analysis-dijikstra-algorithm
<p><img alt="" src="http://gateoverflow.in/?qa=blob&qa_blobid=8992432082143506662">
<br>
<br>
Acc. to dijkstra's algorithm:
<br>
What will be the shortest path from A to B ?
<br>
<br>
1) When the edge of length 15 is present.
<br>
2) when the edge of length 15 is removed.</p>Algorithmshttp://gateoverflow.in/35239/final-analysis-dijikstra-algorithmMon, 11 Jan 2016 21:25:33 +0000common data Linked quetion :- 1) which of the following is correct recurrence formula of I(j) 2)how to evaluate this R.R
http://gateoverflow.in/9345/common-quetion-following-correct-recurrence-formula-evaluate
<p>At the end of it's 5<sup>th</sup> Successful season,The siruseri Permier league is planning to give an award to most improved bowler over 5 years . For this an important Index will be computed for each bowler,This is defined as the longest Subsequence of strictly decreasing economy rate's by the bowler among all his matches over 5 season's.For example seasons are (10.0,5.0,8.9,6.7,4.2,5.5,2.2,3.4,6.0,2.3,2.0) so his improvement index is 7 based on sequence (10.0 ,8.9, 6.7, 5.5, 3.4, 2.3, 2.0) </p>
<p>Now let E[1...........N] Donates a sequence of n economy rates for which improvement index is to be calculated
<br>for 1 $\leq$ j $\leq$ n,Let <strong>I[j]</strong> denotes the improved index for the prefix of score E[1.......j ] ending at <span style="font-family:times new roman,times,serif">E[<strong>j</strong>]</span>
<br>
<br> </p>
<ol>
<li><span style="font-family:tahoma,geneva,sans-serif"><span style="font-size:18px">Which of the following is correct recursive formulation of I(j) ?</span></span>
<br><span style="font-size:12px"><span style="font-family:tahoma,geneva,sans-serif">a) I(1)=1
<br>for j $\in$ 2,3,......,n I(j) = 1+ max {I(k)/ 1$\leq$K<j, E[k] > E[j]}
<br>
<br>b) I(1)=1
<br>for j $\in$2,3,......,n I(j) = 1+E(j-1) if E(j-1)<E(j)
<br>1 otherwise
<br>
<br>C) I(1)=1
<br>for j $\in$2,3,......,n I(j) = 1+ max {I(k)/ 1$\leq$K<j, E[k] < E[j]}
<br>
<br>d)I(1)=1
<br>for j $\in$2,3,......,n I(j) = 1+E(j-1) if E(j-1) > E(j)
<br>1 otherwise </span></span></li>
<li><span style="font-size:18px"><span style="font-family:tahoma,geneva,sans-serif">How to </span>evaluate this Recursive definition Using Dynamic programming?</span>
<br><span style="font-size:12px"><span style="font-family:tahoma,geneva,sans-serif">a) A 2-D table T of Size N X N to be filled row wise from T[1][1] to T[n][n]
<br>
<br>b) A 1-D table T of Size N to be filled from T[n] to T[1]
<br>
<br>C) A 2-D table T of Size N X N to be filled row wise from T[n][n] to T[1][1]
<br>
<br>d) A 1-D table T of Size N to be filled from T[n] to T[1] </span></span></li>
<li><span style="font-size:12px"><span style="font-family:tahoma,geneva,sans-serif"><span style="font-family:tahoma,geneva,sans-serif"><span style="font-family:tahoma,geneva,sans-serif"><span style="font-size:18px">What is the Time complexity in Dynamic programming ?
<br><span style="font-family:tahoma,geneva,sans-serif"><span style="font-size:12px">a) O(n)
<br><span style="font-family:tahoma,geneva,sans-serif"><span style="font-size:12px">b) O(nLog n)
<br><span style="font-family:tahoma,geneva,sans-serif"><span style="font-size:12px">c) O(n<sup>2</sup>)
<br><span style="font-family:tahoma,geneva,sans-serif"><span style="font-size:12px">d) O(n<sup>3</sup>)</span></span></span></span></span></span></span></span></span></span></span></span></span></li></ol>
Algorithmshttp://gateoverflow.in/9345/common-quetion-following-correct-recurrence-formula-evaluateWed, 08 Apr 2015 02:51:20 +0000GATE2011_38
http://gateoverflow.in/2140/gate2011_38
Four Matrices $M_1, M_2, M_3,$ and $M_4$ of dimensions $ p \times q, \:\:q \times r, \:\:r \times s$ and $s \times t$ respectively can be multiplied in several ways with different number of total scalar multiplications. For example when multiplied as $((M_1 \times M_2) \times (M_3 \times M_4))$, the total number of scalar multiplications is $pqr + rst + prt$. When multiplied as $(((M_1 \times M_2) \times M_3) \times M_4)$, the total number of scalar multiplications is $pqr + prs + pst$.<br />
<br />
If $p=10, q=100, r=20, s=5$ and $t=80$, then the minimum number of scalar multiplications needed is<br />
<br />
(A) 248000<br />
<br />
(B) 44000<br />
<br />
(C) 19000<br />
<br />
(D) 25000Algorithmshttp://gateoverflow.in/2140/gate2011_38Mon, 29 Sep 2014 05:20:32 +0000GATE2009-53
http://gateoverflow.in/1338/gate2009-53
<p style="text-align: justify;">A sub-sequence of a given sequence is just the given sequence with some elements (possibly none or all) left out. We are given two sequences $X[m]$ and $Y[n]$ of lengths m and n, respectively with indexes of $X$ and $Y$ starting from $0$.</p>
<p style="text-align: justify;">We wish to find the length of the longest common sub-sequence (LCS) of $X[m]$ and $Y[n]$ as $l(m, n)$, where an incomplete recursive definition for the function $I(i, j)$ to compute the length of the LCS of $X[m]$ and $Y[n]$ is given below:</p>
<pre class="text" style="text-align: justify;">
l(i,j) = 0, if either i = 0 or j = 0
= expr1, if i,j > 0 and X[i-1] = Y[j-1]
= expr2, if i,j > 0 and X[i-1] ≠ Y[j-1]
</pre>
<p style="text-align: justify;">Which one of the following options is correct?</p>
<ol style="list-style-type:upper-alpha">
<li>
<p style="text-align: justify;">$\text{expr1} = l\left(i-1, j\right) +1$</p>
</li>
<li>
<p style="text-align: justify;">$\text{expr1} = l\left(i, j-1\right)$</p>
</li>
<li>
<p style="text-align: justify;">$\text{expr2} = \max\left(l\left(i-1, j\right), l\left(i,j-1\right)\right)$</p>
</li>
<li>
<p style="text-align: justify;">$\text{expr2} = \max\left(l\left(i-1, j-1\right), l\left(i,j\right)\right)$</p>
</li>
</ol>
Algorithmshttp://gateoverflow.in/1338/gate2009-53Mon, 22 Sep 2014 16:19:13 +0000