Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
\f\f\f\f\f\f\f

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions