Skip to content

Beta · Data may be lost.Your data may be reset or lost.

GateBrew
← GATE CSE 2015 Set 2
Questions

Q45

MCQ2 marks, −0.67AlgorithmsMedium

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[ ]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[ ]a[\:] of size nn using the partition function. We assume k≤nk \leq 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 arguments lists are respectively

Sign in to save attempts.

Solutions and discussion are hidden while you attempt this question. They open once you check or show the answer.