Algorithm Design questions — page 1 of 2

Q39

GATE CS 2026 CS-2Algorithm DesignMCQ2 marks−2/3 if wrong
Consider a table TT, where the elements T[i][j],0≤i,j≤nT[i][j], 0 \le i, j \le n, 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:

T[0][k]=T[k][0]=1for k=0,1,2,…,nT[0][k] = T[k][0] = 1 \quad \text{for } k = 0,1,2, \dots, n

T[i][j]=2T[i−1][j]+3T[i][j−1]for 1≤i,j≤nT[i][j] = 2T[i - 1][j] + 3T[i][j - 1] \quad \text{for } 1 \le i, j \le n

Consider the following two algorithms to compute entries of TT. Assume that for both the algorithms, for all 0≤i,j≤n0 \le i, j \le n, T[i][j]T[i][j] has been initialized to 1.

Algorithm B1B_1:
For i = 1, 2, ..., n
 For j = 1, 2, ..., n
 T[i][j] = 2T[i - 1][j] + 3T[i][j - 1]
Algorithm B2B_2:
For s = 2, 3, ..., 2n
 For i = 1, 2, ..., n
 For j = 1, 2, ..., n
 If (i + j == s)
 T[i][j] = 2T[i - 1][j] + 3T[i][j - 1]
Algorithm Bk,k∈{1,2}B_k, k \in \{1,2\} is said to be correct if and only if it calculates the correct values of T[i][j]T[i][j], for all 0≤i,j≤n0 \le i, j \le n, (as per the recursive formulation) at the end of the execution of the algorithm BkB_k.

Which one of the following statements is true?
Show answer without attempting

Answer: A

Q40

GATE CS 2021 CS-1Algorithm DesignMSQ2 marks
Define RnR_n to be the maximum amount earned by cutting a rod of length nn meters into one or more pieces of integer length and selling them. For i > 0, let p[i] denote the selling price of a rod whose length is i meters. Consider the array of prices:
p[1] = 1, p[2] = 5, p[3] = 8, p[4] = 9, p[5] = 10, p[6] = 17, p[7] = 18
Which of the following statements is/are correct about R7R_7?
More than one option can be correct.
Show answer without attempting

Answer: A, C

Q26

GATE CS 2021 CS-2Algorithm DesignMCQ2 marks−2/3 if wrong
Consider the string abbccddeee. Each letter in the string must be assigned a binary code satisfying the following properties:
1. For any two letters, the code assigned to one letter must not be a prefix of the code assigned to the other letter.
2. For any two letters of the same frequency, the letter which occurs earlier in the dictionary order is assigned a code whose length is at most the length of the code assigned to the other letter.
Among the set of all binary code assignments which satisfy the above two properties, what is the minimum length of the encoded string?
Show answer without attempting

Answer: B

Q20

GATE CS 2019 CSAlgorithm DesignNAT1 mark
An array of 25 distinct elements is to be sorted using quicksort. Assume that the pivot element is chosen uniformly at random. The probability that the pivot element gets placed in the worst possible location in the first round of partitioning (rounded off to 2 decimal places) is __________.
Show answer without attempting

Answer: 0.08

Q25

GATE CS 2019 CSAlgorithm DesignNAT1 mark
Consider a sequence of 14 elements: A=[−5,−10,6,3,−1,−2,13,4,−9,−1,4,12,−3,0]A = [-5, -10, 6, 3, -1, -2, 13, 4, -9, -1, 4, 12, -3, 0].
The subsequence sum S(i,j)=∑k=ijA[k]S(i, j) = \sum_{k=i}^j A[k]. Determine the maximum of S(i,j)S(i, j), where 0≤i≤j<140 \le i \le j < 14. (Divide and conquer approach may be used.)

Answer: __________.
Show answer without attempting

Answer: 29

Q31

GATE CS 2018 CSAlgorithm DesignMCQ2 marks−2/3 if wrong
Assume that multiplying a matrix G1G_1 of dimension p×qp \times q with another matrix G2G_2 of dimension q×rq \times r requires pqrpqr scalar multiplications. Computing the product of nn matrices G1G2G3…GnG_1 G_2 G_3 \dots G_n can be done by parenthesizing in different ways. Define GiGi+1G_i G_{i+1} as an explicitly computed pair for a given parenthesization if they are directly multiplied. For example, in the matrix multiplication chain G1G2G3G4G5G6G_1 G_2 G_3 G_4 G_5 G_6 using parenthesization (G1(G2G3))(G4(G5G6))(G_1(G_2 G_3))(G_4(G_5 G_6)), G2G3G_2 G_3 and G5G6G_5 G_6 are the only explicitly computed pairs.

Consider a matrix multiplication chain F1F2F3F4F5F_1 F_2 F_3 F_4 F_5, where matrices F1,F2,F3,F4F_1, F_2, F_3, F_4 and F5F_5 are of dimensions 2×25,25×3,3×16,16×12 \times 25, 25 \times 3, 3 \times 16, 16 \times 1 and 1×10001 \times 1000, respectively. In the parenthesization of F1F2F3F4F5F_1 F_2 F_3 F_4 F_5 that minimizes the total number of scalar multiplications, the explicitly computed pairs is/are
Show answer without attempting

Answer: C

Q48

GATE CS 2018 CSAlgorithm DesignNAT2 marks
Consider the weights and values of items listed below. Note that there is only one unit of each item.
Item numberWeight (in Kgs)Value (in Rupees)
11060
2728
3420
4224
The task is to pick a subset of these items such that their total weight is no more than 11 Kgs and their total value is maximized. Moreover, no item may be split. The total value of items picked by an optimal algorithm is denoted by VoptV_{\text{opt}}. A greedy algorithm sorts the items by their value-to-weight ratios in descending order and packs them greedily, starting from the first item in the ordered list. The total value of items picked by the greedy algorithm is denoted by VgreedyV_{\text{greedy}}.

The value of Vopt−VgreedyV_{\text{opt}} - V_{\text{greedy}} is ____________.
Show answer without attempting

Answer: 16

Q5

GATE CS 2017 CS-1Algorithm DesignMCQ1 mark−1/3 if wrong
Consider the following table:
AlgorithmsDesign Paradigms
(P) Kruskal(i) Divide and Conquer
(Q) Quicksort(ii) Greedy
(R) Floyd-Warshall(iii) Dynamic Programming
Match the algorithms to the design paradigms they are based on.
Show answer without attempting

Answer: C

Q50

GATE CS 2017 CS-2Algorithm DesignNAT2 marks
A message is made up entirely of characters from the set X={P,Q,R,S,T}X = \{P, Q, R, S, T\}. The table of probabilities for each of the characters is shown below:
CharacterProbability
P0.22
Q0.34
R0.17
S0.19
T0.08
Total1.00
If a message of 100 characters over XX is encoded using Huffman coding, then the expected length of the encoded message in bits is ____________.
Show answer without attempting

Answer: 225.0

Q38

GATE CS 2016 CS-2Algorithm DesignNAT2 marks
Let A1,A2,A3A_1, A_2, A_3, and A4A_4 be four matrices of dimensions 10×510 \times 5, 5×205 \times 20, 20×1020 \times 10, and 10×510 \times 5, respectively. The minimum number of scalar multiplications required to find the product A1A2A3A4A_1 A_2 A_3 A_4 using the basic matrix multiplication method is _________.
Show answer without attempting

Answer: 1500.0

Q13

GATE CS 2015 CS-1Algorithm DesignMCQ1 mark−1/3 if wrong
Match the following:

(P) Prim's algorithm for minimum spanning tree
(Q) Floyd-Warshall algorithm for all pairs shortest paths
(R) Mergesort
(S) Hamiltonian circuit

(i) Backtracking
(ii) Greedy method
(iii) Dynamic programming
(iv) Divide and conquer
Show answer without attempting

Answer: C

Q47

GATE CS 2015 CS-2Algorithm DesignMCQ2 marks−2/3 if wrong
Given below are some algorithms, and some algorithm design paradigms.

1. Dijkstra's Shortest Path
2. Floyd-Warshall algorithm to compute all pairs shortest path
3. Binary search on a sorted array
4. Backtracking search on a graph

i. Divide and Conquer
ii. Dynamic Programming
iii. Greedy design
iv. Depth-first search
v. Breadth-first search

Match the above algorithms on the left to the corresponding design paradigm they follow.
Show answer without attempting

Answer: C

Q49

GATE CS 2015 CS-2Algorithm DesignMCQ2 marks−2/3 if wrong
Suppose you are provided with the following function declaration in the C programming language.
int partition(int a[], int n);
The function treats the first element of a[] as a pivot, and rearranges the array so that all elements less than or equal to the pivot is in the left part of the array, and all elements greater than the pivot is in the right part. In addition, it moves the pivot so that the pivot is the last element of the left part. The return value is the number of elements in the left part.

The following partially given function in the C programming language is used to find the kthk^{th} smallest element in an array a[] of size n using the partition function. We assume k≤nk \le n.
int kth_smallest(int a[], int n, int k)
{
    int left_end = partition(a,n);

    if ( left_end+1 == k ){
        return a[left_end];
    }

    if ( left_end+1 > k ){
        return kth_smallest( ____________ );
    } else {
        return kth_smallest( ____________ );
    }
}
The missing argument lists are respectively
Show answer without attempting

Answer: A

Q19

GATE CS 2014 CS-2Algorithm DesignMCQ1 mark−1/3 if wrong
Which one of the following is TRUE?
Show answer without attempting

Answer: C

Q37

GATE CS 2014 CS-2Algorithm DesignNAT2 marks
Consider two strings AA = "qpqrr" and BB = "pqprqrp". Let xx be the length of the longest common subsequence (not necessarily contiguous) between AA and BB and let yy be the number of such longest common subsequences between AA and BB. Then x+10yx + 10y = ___.
Show answer without attempting

Answer: 34

Q38

GATE CS 2014 CS-2Algorithm DesignNAT2 marks
Suppose P, Q, R, S, T are sorted sequences having lengths 20, 24, 30, 35, 50 respectively. They are to be merged into a single sequence by merging together two sequences at a time. The number of comparisons that will be needed in the worst case by the optimal algorithm for doing this is ____.
Show answer without attempting

Answer: 358

Q37

GATE CS 2014 CS-3Algorithm DesignNAT2 marks
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 i,ji, j with i<ji < j. Given a shortcut i,ji, 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 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 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 _____.
Show answer without attempting

Answer: 150

Q18

GATE CS 2014 CS-1Algorithm DesignMCQ1 mark−1/3 if wrong
Match the following:

1) Waterfall model
a) Specifications can be developed incrementally
2) Evolutionary model
b) Requirements compromises are inevitable
3) Component-based software engineering
c) Explicit recognition of risk
4) Spiral development
d) Inflexible partitioning of the project into stages
Show answer without attempting

Answer: B

Q38

GATE CS 2014 CS-1Algorithm DesignMCQ2 marks−2/3 if wrong
Suppose a polynomial time algorithm is discovered that correctly computes the largest clique in a given graph. In this scenario, which one of the following represents the correct Venn diagram of the complexity classes P, NP and NP Complete (NPC)?
Show answer without attempting

Answer: D

Q41

GATE CS 2014 CS-1Algorithm DesignMCQ2 marks−2/3 if wrong
Consider the following C function in which size is the number of elements in the array E:
int MyX(int *E, unsigned int size)
{
  int Y = 0;
  int Z;
  int i, j, k;

  for(i = 0; i < size; i++)
      Y = Y + E[i];

  for(i = 0; i < size; i++)
      for(j = i; j < size; j++)
      {
          Z = 0;
          for(k = i; k <= j; k++)
              Z = Z + E[k];
          if (Z > Y)
              Y = Z;
      }
  return Y;
}
The value returned by the function MyX is the
Show answer without attempting

Answer: A

0/200 correct0 marks

Related topics in Algorithms