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 k-th smallest element in an array a[ ] of size n using the partition function. We assume k <= 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(_______);
}Related Algorithms PYQs
Consider the C function given below. Assume that the array listA contains n (> 0) elements, sorted in ascending order. ```c int Pr…
Suppose we have a balanced binary search tree T holding n numbers. We are given two numbers L and H and wish to sum up all the num…
Which one of the following correctly determines the solution of the recurrence relation with T(1) = 1? T(n) = 2T(n / 2) + log n
Which one of the following is the recurrence equation for the worst case time complexity of the Quicksort algorithm for sorting n …
You have an array of n elements. Suppose you implement quick sort by always choosing the central element of the array as the pivot…
Let P be a quick sort program to sort numbers in ascending order using the first element as the pivot. Let t1 and t2 be the number…
Free account benefits
Turn practice into measurable progress
Public PYQs and reference pages stay free. Sign in when you want GATEverse to remember what you studied and guide what to practise next.