• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

GATE | GATE-CS-2015 (Set 2) | Question 55

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[] 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 kth smallest element in an array a[ ] of size n using the partition function. We assume k ≤ n C
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 argument lists are respectively

(A)

(a, left_end, k) and (a+left_end+1, n–left_end–1, k–left_end–1)

(B)

(a, left_end, k) and (a, n–left_end–1, k–left_end–1)

(C)

(a, left_end+1, N–left_end–1, K–left_end–1) and(a, left_end, k)

(D)

(a, n–left_end–1, k–left_end–1) and (a, left_end, k)

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments