Algorithms questions — page 4 of 7

Q30

GATE CS 2018 CSGraph AlgorithmsMCQ2 marks−2/3 if wrong
Let GG be a simple undirected graph. Let TDT_D be a depth first search tree of GG. Let TBT_B be a breadth first search tree of GG. Consider the following statements.

(I) No edge of GG is a cross edge with respect to TDT_D. (A cross edge in GG is between two nodes neither of which is an ancestor of the other in TDT_D.)
(II) For every edge (u,v)(u, v) of GG, if uu is at depth ii and vv is at depth jj in TBT_B, then ∣i−j∣=1|i - j| = 1.

Which of the statements above must necessarily be true?
Show answer without attempting

Answer: A

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

Q47

GATE CS 2018 CSGraph AlgorithmsNAT2 marks
Consider the following undirected graph G:

Choose a value for xx that will maximize the number of minimum weight spanning trees (MWSTs) of G. The number of MWSTs of G for this value of xx is ______.
Question figure
Show answer without attempting

Answer: 4

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

Q4

GATE CS 2017 CS-1Algorithm AnalysisMCQ1 mark−1/3 if wrong
Consider the following functions from positive integers to real numbers:

10,n,n,log⁡2n,100n10, \sqrt{n}, n, \log_2 n, \frac{100}{n}

The CORRECT arrangement of the above functions in increasing order of asymptotic complexity is:
Show answer without attempting

Answer: B

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

Q26

GATE CS 2017 CS-1Graph AlgorithmsMCQ2 marks−2/3 if wrong
Let G=(V,E)G = (V, E) be any connected undirected edge-weighted graph. The weights of the edges in EE are positive and distinct. Consider the following statements:

(I) Minimum Spanning Tree of GG is always unique.
(II) Shortest path between any two vertices of GG is always unique.

Which of the above statements is/are necessarily true?
Show answer without attempting

Answer: A

Q48

GATE CS 2017 CS-1Searching Sorting and HashingNAT2 marks
Let AA be an array of 3131 numbers consisting of a sequence of 00's followed by a sequence of 11's. The problem is to find the smallest index ii such that A[i]A[i] is 11 by probing the minimum number of locations in AA. The worst case number of probes performed by an optimal algorithm is ____________.
Show answer without attempting

Answer: 5.0

Q3

GATE CS 2017 CS-2Algorithm AnalysisMCQ1 mark−1/3 if wrong
Match the algorithms with their time complexities:
AlgorithmTime complexity
(P) Towers of Hanoi with nn disks(i) Θ(n2)\Theta(n^2)
(Q) Binary search given nn sorted numbers(ii) Θ(nlog⁡n)\Theta(n \log n)
(R) Heap sort given nn numbers at the worst case(iii) Θ(2n)\Theta(2^n)
(S) Addition of two n×nn \times n matrices(iv) Θ(log⁡n)\Theta(\log n)
Show answer without attempting

Answer: C

Q15

GATE CS 2017 CS-2Graph AlgorithmsMCQ1 mark−1/3 if wrong
The Breadth First Search (BFS) algorithm has been implemented using the queue data structure. Which one of the following is a possible order of visiting the nodes in the graph below?
Question figure
Show answer without attempting

Answer: D

Q30

GATE CS 2017 CS-2Algorithm AnalysisMCQ2 marks−2/3 if wrong
Consider the recurrence function
T(n)={2T(n)+1,n>22,0<n≤2T(n) = \begin{cases} 2T(\sqrt{n}) + 1, & n > 2 \\ 2, & 0 < n \le 2 \end{cases}
Then T(n)T(n) in terms of Θ\Theta notation is
Show answer without attempting

Answer: B

Q38

GATE CS 2017 CS-2Algorithm AnalysisMCQ2 marks−2/3 if wrong
Consider the following C function.
int fun(int n) {
    int i, j;
    for (i = 1; i <= n; i++) {
        for (j = 1; j < n; j += i) {
            printf(" %d %d", i, j);
        }
    }
}
Time complexity of fun in terms of Θ\Theta notation is
Show answer without attempting

Answer: C

Q43

GATE CS 2017 CS-2Searching Sorting and HashingNAT2 marks
Consider the following snippet of a C program. Assume that swap(&x, &y) exchanges the contents of xx and yy.
int main() {
    int array[] = {3, 5, 1, 4, 6, 2};
    int done = 0;
    int i;
    while (done == 0) {
        done = 1;
        for (i=0; i<=4; i++) {
            if (array[i] < array[i+1]) {
                swap(&array[i], &array[i+1]);
                done = 0;
            }
        }
        for (i=5; i>=1; i--) {
            if (array[i] > array[i-1]) {
                swap(&array[i], &array[i-1]);
                done = 0;
            }
        }
    }
    printf("%d", array[3]);
}
The output of the program is ____________.
Show answer without attempting

Answer: 3.0

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

Q11

GATE CS 2016 CS-1Graph AlgorithmsNAT1 mark
Consider the following directed graph:

The number of different topological orderings of the vertices of the graph is ________.
Question figure
Show answer without attempting

Answer: 6.0

Q13

GATE CS 2016 CS-1Searching Sorting and HashingMCQ1 mark−1/3 if wrong
The worst case running times of Insertion sort, Merge sort and Quick sort, respectively, are:
Show answer without attempting

Answer: D

Q14

GATE CS 2016 CS-1Graph AlgorithmsMCQ1 mark−1/3 if wrong
Let GG be a weighted connected undirected graph with distinct positive edge weights. If every edge weight is increased by the same value, then which of the following statements is/are TRUE?

P: Minimum spanning tree of GG does not change
Q: Shortest path between any pair of vertices does not change
Show answer without attempting

Answer: A

Q38

GATE CS 2016 CS-1Graph AlgorithmsNAT2 marks
Consider the weighted undirected graph with 4 vertices, where the weight of edge {i, j} is given by the entry WijW_{ij} in the matrix WW.

W=[02852058850x58x0]W = \begin{bmatrix} 0 & 2 & 8 & 5 \\ 2 & 0 & 5 & 8 \\ 8 & 5 & 0 & x \\ 5 & 8 & x & 0 \end{bmatrix}

The largest possible integer value of x, for which at least one shortest path between some pair of vertices will contain the edge with weight x is ________.
Show answer without attempting

Answer: 12.0

Q39

GATE CS 2016 CS-1Graph AlgorithmsNAT2 marks
Let G be a complete undirected graph on 4 vertices, having 6 edges with weights being 1, 2, 3, 4, 5, and 6. The maximum possible weight that a minimum weight spanning tree of G can have is ________.
Show answer without attempting

Answer: 7.0

Q40

GATE CS 2016 CS-1Graph AlgorithmsMCQ2 marks−2/3 if wrong
G = (V,E) is an undirected simple graph in which each edge has a distinct weight, and e is a particular edge of G. Which of the following statements about the minimum spanning trees (MSTs) of G is/are TRUE?

I. If e is the lightest edge of some cycle in G, then every MST of G includes e
II. If e is the heaviest edge of some cycle in G, then every MST of G excludes e
Show answer without attempting

Answer: B

0/200 correct0 marks

Related topics in GATE CS