GATE CS Algorithm Design: Dynamic Programming questions
Practise Algorithm Design: Dynamic Programming questions for GATE CS. Explore official PYQs and original topic-wise quizzes, check answers and view available solutions. Free, no sign-in.
Identify the state, recurrence and base cases before choosing memoisation or tabulation. Compare related problems to recognise overlapping subproblems.
Subject, topic, year and type filter the full library. Match any choice within a filter, and all selected filter categories. Search, source and sort apply to this page.
17 on this page
Consider a table , where the elements , represent the cost of the optimal solutions of different subproblems of a problem that is being solved using a dynamic programming algorithm. The recursive formulation to compute the table entries is as follows: …
Assume that multiplying a matrix of dimension with another matrix of dimension requires scalar multiplications. Computing the product of matrices can be done by parenthesizing in different ways. Define as an explicitly computed pair for a given …
Let and be four matrices of dimensions and , respectively. The minimum number of scalar multiplications required to find the product using the basic matrix multiplication method is _________.
The Floyd-Warshall algorithm for all-pair shortest paths computation is based on
Consider two strings = "qpqrr" and = "pqprqrp". Let be the length of the longest common subsequence (not necessarily contiguous) between and and let be the number of such longest common subsequences between and . Then ___.
Suppose you want to move from to 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 . Given a shortcut , if you are at position on the number line, you may directly move to . Suppose …
Consider the following recursive C function that takes two arguments. unsigned int foo(unsigned int n, unsigned int r) { if (n>0) return ((n%r) + foo(n/r, r)); else return 0; } What is the return value of the function when it is called as ?
Consider the following recursive C function that takes two arguments. unsigned int foo(unsigned int n, unsigned int r) { if (n>0) return ((n%r) + foo(n/r, r)); else return 0; } What is the return value of the function when it is called as ?
Four Matrices and of dimensions and respectively can be multiplied in several ways with different number of total scalar multiplications. For example when multiplied as , the total number of scalar multiplications is …
An algorithm to find the length of the longest monotonically increasing sequence of numbers in an array is given below. Let , denote the length of the longest monotonically increasing sequence starting at index in the array. Initialize . For all such that …
What is the value printed by the following C program? #include<stdio.h> int f(int *a, int n) { if (n <= 0) return 0; else if (*a % 2 == 0) return *a+f(a+1, n-1); else return *a - f(a+1, n-1); } int main() { int a[] = {12, 7, 13, 4, 11, 6}; printf("%d", f(a, 6)); return 0; }
The weight of a sequence of real numbers is defined as . A subsequence of a sequence is obtained by deleting some elements from the sequence, keeping the order of the remaining elements the same. Let denote the maximum possible weight of a subsequence of and …
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 and of lengths and , respectively with indexes of and starting from . We wish to find the length of the longest common sub-sequence (LCS) of and as …
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 and of lengths and , respectively with indexes of and starting from . We wish to find the length of the longest common sub-sequence (LCS) of and as …
Consider the program below: #include <stdio.h> int fun(int n, int *f_p) { int t, f; if (n <= 1) { *f_p = 1; return 1; } t = fun(n-1, f_p); f = t + *f_p; *f_p = t; return f; } int main() { int x = 15; printf("%d/n", fun(5, &x)); return 0; } The value printed is:
The subset-sum problem is defined as follows. Given a set of positive integers, , and positive integer , is there a subset of whose elements sum to ? A dynamic program for solving this problem uses a Boolean array, , with rows and columns. …
The subset-sum problem is defined as follows. Given a set of positive integers, , and positive integer , is there a subset of whose elements sum to ? A dynamic program for solving this problem uses a Boolean array, , with rows and columns. …
