PA of Algorithms Q111

0. 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.

  • Option : A
  • Explanation :
    When we put (a, left–End, K) and (a+ left – end + 1, n– left – end –1, k– left–end –1)at the place of fill in the blank algorithm work for partition.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *