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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started