Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

kSmall:C++ 11 K'th Smallest Element in an Array Hello, please provide an example of code for the following question: Find the K'th smallest element of

kSmall:C++ 11 K'th Smallest Element in an Array

Hello, please provide an example of code for the following question:

Find the K'th smallest element of an array using the recursive function kSmall. Implement the algorithm kSmall, which has the following psuedocode:

kSmall (k:integer, anArray:ArrayType, first:integer, last:integer): ValueType { choose a pivot value p from anArray [first...last] partition the values of anArray[first...last] about p if (k< pivotIndex -first +1) return kSmall(k, anArray, first, pivotIndex-1) else if (k== pivotIndex - first + 1) return p else return kSmall(k-(pivotIndex-first+1), anArray, pivotIndex+1, last) } Implement the partitioning of the array as a function separate from kSmall. Please use Lomutos algorithm for the partitioning (https://en.wikipedia.org/wiki/Quicksort#Lomuto_partition_scheme), if possible.

Develop a main program that creates a built-in array filled with 20 random integers to test kSmall. Use kSmall to find the 3rd, 10th, and 15th smallest integers in the array. Output the results.

For reference here is a similar chegg question: http://www.chegg.com/homework-help/questions-and-answers/implement-algorithm-ksmall-c-function-use-first-value-array-pivot-use-main-file-tests-clas-q15111279 However, the referenced question and answer is more complex than this question. There is no need to read a file and fill an array with its contents, just have a built-in array of integers. Also, there is no need for a log file.

Thank you.

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

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

More Books

Students also viewed these Databases questions

Question

Psychological, financial, and career counseling.

Answered: 1 week ago