Searching Sorting and Hashing questions

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

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

0/20 correct0 marks

Related topics in Algorithms