Sorting questions

Q32

GATE CS 2026 CS-2Searching Sorting and HashingNAT1 mark
Consider an array A=[10,7,8,19,41,35,25,31]A = [10, 7, 8, 19, 41, 35, 25, 31]. Suppose the merge sort algorithm is executed on array AA to sort it in increasing order. The merge sort algorithm will carry out a total of 7 merge operations.

A merge operation on sorted left array LL and sorted right array RR is said to be void if the output of the merge operation is the elements of array LL followed by the elements of array RR.

The number of void merge operations among these 7 merge operations is __________. (answer in integer)
Show answer without attempting

Answer: 3

Q33

GATE CS 2025 CS-1Searching Sorting and HashingNAT1 mark
The pseudocode of a function fun() is given below:
fun(int A[0,\dots,n-1]){
 for i=0 to n-2
 for j=0 to n-i-2
 if (A[j]>A[j+1])
 then swap A[j] and A[j+1]
}
Let A[0,…,29]A[0, \dots, 29] be an array storing 30 distinct integers in descending order. The number of swap operations that will be performed, if the function fun() is called with A[0,…,29]A[0, \dots, 29] as argument, is __________. (Answer in integer)
Show answer without attempting

Answer: 435

Q9

GATE CS 2021 CS-1Searching Sorting and HashingMCQ1 mark−1/3 if wrong
Consider the following array.
2332456972738997
Which algorithm out of the following options uses the least number of comparisons (among the array elements) to sort the above array in ascending order?
Show answer without attempting

Answer: C

Q37

GATE CS 2019 CSSearching Sorting and HashingMCQ2 marks−2/3 if wrong
There are nn unsorted arrays: A1,A2,...,AnA_1, A_2, ..., A_n. Assume that nn is odd. Each of A1,A2,...,AnA_1, A_2, ..., A_n contains nn distinct elements. There are no common elements between any two arrays. The worst-case time complexity of computing the median of the medians of A1,A2,...,AnA_1, A_2, ..., A_n 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

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

Q13

GATE CS 2016 CS-2Searching Sorting and HashingMCQ1 mark−1/3 if wrong
Assume that the algorithms considered here sort the input sequences in ascending order. If the input is already in ascending order, which of the following are TRUE?

I. Quicksort runs in Θ(n2)\Theta(n^2) time
II. Bubblesort runs in Θ(n2)\Theta(n^2) time
III. Mergesort runs in Θ(n)\Theta(n) time
IV. Insertion sort runs in Θ(n)\Theta(n) time
Show answer without attempting

Answer: D

Q14

GATE CS 2014 CS-3Searching Sorting and HashingMCQ1 mark−1/3 if wrong
You have an array of nn elements. Suppose you implement quicksort by always choosing the central element of the array as the pivot. Then the tightest upper bound for the worst case performance is
Show answer without attempting

Answer: A

Q14

GATE CS 2014 CS-1Searching Sorting and HashingMCQ1 mark−1/3 if wrong
Let PP be a quicksort program to sort numbers in ascending order using the first element as the pivot. Let t1t_1 and t2t_2 be the number of comparisons made by PP for the inputs [1  2  3  4  5][1\;2\;3\;4\;5] and [4  1  5  3  2][4\;1\;5\;3\;2] respectively. Which one of the following holds?
Show answer without attempting

Answer: C

Q6

GATE CS 2013 CSSearching Sorting and HashingMCQ1 mark−1/3 if wrong
Which one of the following is the tightest upper bound that represents the number of swaps required to sort nn numbers using selection sort?
Show answer without attempting

Answer: B

Q30

GATE CS 2013 CSSearching Sorting and HashingMCQ2 marks−2/3 if wrong
The number of elements that can be sorted in Θ(log⁡n)\Theta(\log n) time using heap sort is
Show answer without attempting

Answer: C

Q39

GATE CS 2012 CSSearching Sorting and HashingMCQ2 marks−2/3 if wrong
A list of nn strings, each of length nn, is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation is
Show answer without attempting

Answer: Marks to all

0/120 correct0 marks

Related topics in Searching Sorting and Hashing