Question: Find the nth ranked number (recursive): For this task you have to make a recursive C function, kSmall(), that returns the k th smallest number

Find the nth ranked number (recursive):

For this task you have to make a recursive C function, kSmall(), that returns the kthsmallest number from a set given as an array. You will be implementing a famous algorithm 'ksmall' for this task. The algorithm has two basic steps.

Step 1: Partition the data around a pivot value such that all the elements to the left of pivot index are smaller than the pivot value and the ones to the right are greater than the pivot value.

Step 2: Recursively call the function 'kSmall()', on the partition that contains the kth smallest element. Details are given in the attached document.

For this task, you are already given the function for implementing the partitioning step. It has the following prototype:

int partition_array(float * ptr_array, int size);

Given an input array, the partition_array() function chooses some element p (called the pivot), then rearranges the array so that

All elements less than or equal to p are before p.

All elements greater than p are after p.

p is in the position it would occupy if the array were sorted.

The function then returns the index of p.

The prototype for the function that you have to complete is given below:

float kSmall(float * ptr_array, int size, int k);

Domain Knowledge:

See the attached pics for the background of the problem and the actual recursive algorithm

It is from C language not C++.

Please use the given prototype in the program.

Find the nth ranked number (recursive):For this task you have to makea recursive C function, kSmall(), that returns the kthsmallest number from aset given as an array. You will be implementing a famous algorithm'ksmall' for this task. The algorithm has two basic steps. Step 1:Partition the data around a pivot value such that all the elementsto the left of pivot index are smaller than the pivot valueand the ones to the right are greater than the pivot value.Step

\f\f\f\f\f\f\f

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!