Algorithms questions

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

0/100 correct0 marks

Related topics in GATE CS