GATE Overflow - Recent questions tagged dynamic-programming
https://gateoverflow.in/tag/dynamic-programming
Powered by Question2AnswerCLRS Divide-and-Conquer Strassens's algorithm
https://gateoverflow.in/158752/clrs-divide-and-conquer-strassenss-algorithm
Do we need to study the Strassens's algorithm in detail like proof or working of that algorithm or we just need to know the time complexity of the algorithm because I can't find it's explanation anywhere?Algorithmshttps://gateoverflow.in/158752/clrs-divide-and-conquer-strassenss-algorithmMon, 09 Oct 2017 16:56:10 +0000Matrix Chain
https://gateoverflow.in/156571/matrix-chain
Total no. of ways to perform matrix multiplication having 7 matrices is ?<br />
<br />
Total no. of ways to by which we could parenthesize 7 matrices is ?<br />
<br />
Does the above two questions are different or same ?<br />
<br />
Plz explain the answer.Algorithmshttps://gateoverflow.in/156571/matrix-chainSun, 01 Oct 2017 16:35:42 +0000DYNAMIC PROGRAMMING
https://gateoverflow.in/153014/dynamic-programming
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=16999013844290231030"></p>Algorithmshttps://gateoverflow.in/153014/dynamic-programmingSun, 17 Sep 2017 19:34:26 +0000dynamic programming
https://gateoverflow.in/153012/dynamic-programming
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=5911305427616727440"></p>Algorithmshttps://gateoverflow.in/153012/dynamic-programmingSun, 17 Sep 2017 19:32:09 +0000Floyd-warshall for longest path problem
https://gateoverflow.in/150765/floyd-warshall-for-longest-path-problem
<p>I have few doubts related to Longest distance problem. From Wikipedia --></p>
<blockquote>
<p>The NP-hardness of the unweighted longest path problem can be shown using a reduction from the <a rel="nofollow" href="https://en.wikipedia.org/wiki/Hamiltonian_path_problem">Hamiltonian path problem</a>: a graph <em>G</em> has a Hamiltonian path if and only if its longest path has length <em>n</em> − 1, where <em>n</em> is the number of vertices in <em>G</em>. Because the Hamiltonian path problem is NP-complete, this reduction shows that the <a rel="nofollow" href="https://en.wikipedia.org/wiki/Decision_problem">decision version</a> of the longest path problem is also NP-complete. In this decision problem, the input is a graph <em>G</em> and a number <em>k</em>; the desired output is "yes" if <em>G</em> contains a path of <em>k</em> or more edges, and <em>no</em> otherwise.<sup><a rel="nofollow" href="https://en.wikipedia.org/wiki/Longest_path_problem#cite_note-1">[1]</a></sup></p>
<p>If the longest path problem could be solved in polynomial time, it could be used to solve this decision problem, by finding a longest path and then comparing its length to the number <em>k</em>. Therefore, the longest path problem is NP-hard. It is not NP-complete, because it is not a decision problem.<sup><a rel="nofollow" href="https://en.wikipedia.org/wiki/Longest_path_problem#cite_note-2">[2]</a></sup></p>
<p>In weighted <a rel="nofollow" href="https://en.wikipedia.org/wiki/Complete_graph">complete graphs</a> with non-negative edge weights, the weighted longest path problem is the same as the <a rel="nofollow" href="https://en.wikipedia.org/wiki/Travelling_salesman_problem">Travelling salesman path problem</a>, because the longest path always includes all vertices.<sup><a rel="nofollow" href="https://en.wikipedia.org/wiki/Longest_path_problem#cite_note-3">[3]</a> </sup></p>
<p>However, it has a <a rel="nofollow" href="https://en.wikipedia.org/wiki/Linear_time">linear time</a> solution for <a rel="nofollow" href="https://en.wikipedia.org/wiki/Directed_acyclic_graph">directed acyclic graphs</a>, which has important applications in finding the <a rel="nofollow" href="https://en.wikipedia.org/wiki/Critical_path_method">critical path</a> in scheduling problems.</p>
</blockquote>
<p> </p>
<p>Means in some special cases Longest path problem comes under P-class. </p>
<p>So my doubts are --></p>
<ul>
<li>What is the algorithm For finding Longest path in directed acyclic graphs ?</li>
<li>Why modified Floyd-Warshall algorithm could not be used for finding Longest path in general (means why does it fails) ?
<ul>
<li>Some modification like instead of taking min can not we take Max or </li>
<li>Change positive edge weight to negative then use normal algorithm as asked in (<a rel="nofollow" href="https://stackoverflow.com/questions/42500120/floyd-warshall-for-longest-distance-for-undirected-graph">https://stackoverflow.com/questions/42500120/floyd-warshall-for-longest-distance-for-undirected-graph</a>)</li>
</ul>
</li>
</ul>
<p> </p>Algorithmshttps://gateoverflow.in/150765/floyd-warshall-for-longest-path-problemFri, 08 Sep 2017 14:16:22 +0000dynamic programming
https://gateoverflow.in/147234/dynamic-programming
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=1993827809154770957"></p>Algorithmshttps://gateoverflow.in/147234/dynamic-programmingSat, 26 Aug 2017 02:25:09 +0000Longest Common Subsequence
https://gateoverflow.in/130035/longest-common-subsequence
For finding longest common subsequence(LCS), standard sources mention that the recursive procedure consisting of the recursive tree occupies O(m+n) space( WITHOUT applying Dynamic Programming). I am unable to understand why is space occupied O(m+n)?<br />
<br />
Consider the tree of LCS(3,3). Won't the tree height( which is equal to the height of recursion stack and hence space occupied) be equivalent to log of (m+n), as in, the sequence can be evaluated as 2^0+2^1^2^2+...................2^k(worst case) where k will be the number of levels. So, the value of2^ k = O(m+n) and hence, space should be k=log(m+n).<br />
<br />
What's wrong with my logic?Algorithmshttps://gateoverflow.in/130035/longest-common-subsequenceWed, 17 May 2017 19:50:30 +0000difference between dynamic programming and divide and conquer technique is
https://gateoverflow.in/125936/difference-between-dynamic-programming-conquer-technique
What is the difference between dynamic programming and divide and conquer technique,Algorithmshttps://gateoverflow.in/125936/difference-between-dynamic-programming-conquer-techniqueMon, 17 Apr 2017 13:16:14 +0000Dynamic Programming
https://gateoverflow.in/122246/dynamic-programming
Find an optimal parenthesization of a matrix-chain product whose sequence of di-mensions<br />
<5,10,3,12,5,50,6>.Algorithmshttps://gateoverflow.in/122246/dynamic-programmingTue, 21 Mar 2017 11:16:38 +0000What is the general idea to approach to problems in Dynamic Programming ?
https://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>Algorithmshttps://gateoverflow.in/101336/what-the-general-idea-approach-problems-dynamic-programmingFri, 06 Jan 2017 10:43:45 +0000Made Easy Test Series
https://gateoverflow.in/100103/made-easy-test-series
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=16494035913491667731"></p>Algorithmshttps://gateoverflow.in/100103/made-easy-test-seriesTue, 03 Jan 2017 20:40:18 +0000virtual gate
https://gateoverflow.in/98211/virtual-gate
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=17764619701595438412"></p>Algorithmshttps://gateoverflow.in/98211/virtual-gateFri, 30 Dec 2016 00:14:58 +0000Find shortest path
https://gateoverflow.in/86958/find-shortest-path
<p><img alt="" height="400" src="https://gateoverflow.in/?qa=blob&qa_blobid=12914640239353443282" width="1101"></p>Algorithmshttps://gateoverflow.in/86958/find-shortest-pathSun, 27 Nov 2016 11:53:14 +0000Divide and conquer+Dynamic
https://gateoverflow.in/72538/divide-and-conquer-dynamic
<p><img alt="Loading Question" src="https://d2190hpfa85jkd.cloudfront.net/q/b447cbf84ec3a8edd819eeb39fc6523f.jpg"></p>Algorithmshttps://gateoverflow.in/72538/divide-and-conquer-dynamicSat, 08 Oct 2016 17:09:29 +0000Recurrence relation and probability
https://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>https://gateoverflow.in/64328/recurrence-relation-and-probabilityTue, 23 Aug 2016 00:23:56 +0000UGCNET-Dec2013-III-37
https://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>Algorithmshttps://gateoverflow.in/60569/ugcnet-dec2013-iii-37Thu, 28 Jul 2016 08:24:45 +0000Maximum Continuous Sum in an Array
https://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 Challengeshttps://gateoverflow.in/55422/maximum-continuous-sum-in-an-arraySun, 03 Jul 2016 12:00:23 +0000CMI2013-B-06b
https://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>
Algorithmshttps://gateoverflow.in/49177/cmi2013-b-06bWed, 08 Jun 2016 12:47:00 +0000CMI2015-B-07
https://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>
Algorithmshttps://gateoverflow.in/47071/cmi2015-b-07Fri, 27 May 2016 13:14:32 +0000CMI2014-B-05
https://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.Algorithmshttps://gateoverflow.in/46985/cmi2014-b-05Fri, 27 May 2016 08:26:58 +0000What is the time complexity of Binary Knapsack?
https://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>
Algorithmshttps://gateoverflow.in/46580/what-is-the-time-complexity-of-binary-knapsackMon, 23 May 2016 11:48:35 +0000CMI2012-B-06
https://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.Algorithmshttps://gateoverflow.in/46569/cmi2012-b-06Mon, 23 May 2016 09:21:51 +0000GATE2008-81
https://gateoverflow.in/43484/gate2008-81
<p>The subset-sum problem is defined as follows. Given a set of $n$ positive integers, $S = \{ a_1, a_2, a_3, \dots , a_n \}$, and positive integer $W$, is there a subset of $S$ whose elements sum to $W$? A dynamic program for solving this problem uses a 2-dimensional Boolean array, $X$, with $n$ rows and $W+1$ columns. $X[i, j], 1 \leq i \leq n, 0 \leq j \leq W$, is TRUE, if and only if there is a subset of $\{a_1, a_2, \dots, a_i\}$ whose elements sum to $j$.</p>
<p>Which entry of the array $X$, if TRUE, implies that there is a subset whose elements sum to $W$?</p>
<ol style="list-style-type:upper-alpha">
<li>$X[1, W]$</li>
<li>$X[n, 0]$</li>
<li>$X[n, W]$</li>
<li>$X[n-1, n]$</li>
</ol>Algorithmshttps://gateoverflow.in/43484/gate2008-81Sat, 23 Apr 2016 09:15:49 +0000GATE2009-54
https://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>Algorithmshttps://gateoverflow.in/43476/gate2009-54Sat, 23 Apr 2016 08:52: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?
https://gateoverflow.in/42390/southeast-northwest-corner-chess-board-travels-only-upwards
Combinatoryhttps://gateoverflow.in/42390/southeast-northwest-corner-chess-board-travels-only-upwardsSun, 10 Apr 2016 07:12:14 +0000GATE2016-2-38
https://gateoverflow.in/39587/gate2016-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 _________.Algorithmshttps://gateoverflow.in/39587/gate2016-2-38Fri, 12 Feb 2016 13:02:21 +0000GATE2016-2-14
https://gateoverflow.in/39570/gate2016-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>Algorithmshttps://gateoverflow.in/39570/gate2016-2-14Fri, 12 Feb 2016 12:16:38 +0000Final Analysis DIJIKSTRA ALGORITHM
https://gateoverflow.in/35239/final-analysis-dijikstra-algorithm
<p><img alt="" src="https://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>Algorithmshttps://gateoverflow.in/35239/final-analysis-dijikstra-algorithmTue, 12 Jan 2016 02:55:33 +0000common data Linked quetion :- 1) which of the following is correct recurrence formula of I(j) 2)how to evaluate this R.R
https://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>
Algorithmshttps://gateoverflow.in/9345/common-quetion-following-correct-recurrence-formula-evaluateWed, 08 Apr 2015 08:21:20 +0000GATE2010-34
https://gateoverflow.in/2208/gate2010-34
<p>The weight of a sequence $a_0,a_1, \dots, a_{n-1}$ of real numbers is defined as $a_0+a_1/2+ \dots + a_{n-1}/2^{n-1}$. A subsequence of a sequence is obtained by deleting some elements from the sequence, keeping the order of the remaining elements the same. Let $X$ denote the maximum possible weight of a subsequence of $a_o,a_1, \dots, a_{n-1}$ and $Y$ the maximum possible weight of a subsequence of $a_1,a_2, \dots, a_{n-1}$. Then $X$ is equal to</p>
<ol style="list-style-type:upper-alpha">
<li>$max(Y, a_0+Y)$</li>
<li>$max(Y, a_0+Y/2)$</li>
<li>$max(Y, a_0 +2Y)$</li>
<li>$a_0+Y/2$</li>
</ol>Algorithmshttps://gateoverflow.in/2208/gate2010-34Mon, 29 Sep 2014 15:23:23 +0000GATE2011_38
https://gateoverflow.in/2140/gate2011_38
<p>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</p>
<ol style="list-style-type: upper-alpha;">
<li> 248000</li>
<li> 44000</li>
<li> 19000</li>
<li> 25000</li>
</ol>Algorithmshttps://gateoverflow.in/2140/gate2011_38Mon, 29 Sep 2014 10:50:32 +0000GATE2011-25
https://gateoverflow.in/2127/gate2011-25
<p>An algorithm to find the length of the longest monotonically increasing sequence of numbers in an array $A[0:n-1]$ is given below.</p>
<p>Let $L_i$, denote the length of the longest monotonically increasing sequence starting at index $i$ in the array.</p>
<p>Initialize $L_{n-1} = 1$.</p>
<p>For all $i$ such that $0 \leq i \leq n-2$</p>
<p>$ L_i = \begin{cases} 1+ L_{i+1} & \quad\text{if A[i] < A[i+1]} \\ 1 & \quad\text{Otherwise}\end{cases} $</p>
<p>Finally the the length of the longest monotonically increasing sequence is $\text{Max} \:(L_0, L_1, \dots , L_{n-1}).$</p>
<p>Which of the following statements is <strong>TRUE</strong>?</p>
<ol style="list-style-type:upper-alpha">
<li>The algorithm uses dynamic programming paradigm</li>
<li>The algorithm has a linear complexity and uses branch and bound paradigm</li>
<li>The algorithm has a non-linear polynomial complexity and uses branch and bound paradigm</li>
<li>The algorithm uses divide and conquer paradigm</li>
</ol>Algorithmshttps://gateoverflow.in/2127/gate2011-25Mon, 29 Sep 2014 10:27:42 +0000GATE2014-3-37
https://gateoverflow.in/2071/gate2014-3-37
<p>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 <em>shortcut</em>. A shortcut is simply a pre-specified pair of integers $i,\:j \:\text{with}\: i <j$. Given a shortcut $i,j$ if you are at position $i$ on the number line, you may directly move to $j$. Suppose $T(k)$ denotes the smallest number of steps needed to move from $k$ 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 $y$ and $z$ be such that $T(9) = 1 + \min(T(y),T(z))$. Then the value of the product $yz$ is _____.</p>Algorithmshttps://gateoverflow.in/2071/gate2014-3-37Sun, 28 Sep 2014 15:15:30 +0000GATE2014-2-37
https://gateoverflow.in/1996/gate2014-2-37
<p>Consider two strings $A$=<em>"qpqrr"</em> and $B$=<em>"pqprqrp"</em>. Let $x$ be the length of the longest common subsequence <em>(not necessarily contiguous) </em>between $A$ and $B$ and let $y$ be the number of such longest common subsequences between $A$ and $B$. Then $x +10y=$ ___.</p>Algorithmshttps://gateoverflow.in/1996/gate2014-2-37Sun, 28 Sep 2014 11:57:58 +0000GATE2009-53
https://gateoverflow.in/1338/gate2009-53
<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>
<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>Which one of the following options is correct?</p>
<ol style="list-style-type:upper-alpha">
<li>
<p>$\text{expr1} = l\left(i-1, j\right) +1$</p>
</li>
<li>
<p>$\text{expr1} = l\left(i, j-1\right)$</p>
</li>
<li>
<p>$\text{expr2} = \max\left(l\left(i-1, j\right), l\left(i,j-1\right)\right)$</p>
</li>
<li>
<p>$\text{expr2} = \max\left(l\left(i-1, j-1\right), l\left(i,j\right)\right)$</p>
</li>
</ol>Algorithmshttps://gateoverflow.in/1338/gate2009-53Mon, 22 Sep 2014 21:49:13 +0000GATE2008-80
https://gateoverflow.in/498/gate2008-80
<p>The subset-sum problem is defined as follows. Given a set of $n$ positive integers, $S = \{ a_1, a_2, a_3, \dots , a_n \}$, and positive integer $W$, is there a subset of $S$ whose elements sum to $W$? A dynamic program for solving this problem uses a 2-dimensional Boolean array, $X$, with $n$ rows and $W+1$ columns. $X[i, j], 1 \leq i \leq n, 0 \leq j \leq W$, is TRUE, if and only if there is a subset of $\{a_1, a_2, \dots, a_i\}$ whose elements sum to $j$.</p>
<p>Which of the following is valid for $2 \leq i \leq n$, and $a_i \leq j \leq W$?</p>
<ol style="list-style-type:upper-alpha">
<li>$X[i, j] = X[i-1, j] \vee X[i, j-a_i]$</li>
<li>$X[i, j] = X[i-1, j] \vee X[i-1, j-a_i]$</li>
<li>$X[i, j] = X[i-1, j] \wedge X[i, j-a_i]$</li>
<li>$X[i, j] = X[i-1, j] \wedge X[i-1, j-a_i]$</li>
</ol>Algorithmshttps://gateoverflow.in/498/gate2008-80Fri, 12 Sep 2014 21:40:13 +0000