Question: Using C + + ! ! 5 . 7 LAB: Finding the k - max values In the cases where we are presented a large

Using C++!!5.7 LAB: Finding the k-max values
In the cases where we are presented a large set of data, it is typical to sort the data to make searches easier.
We know that a good sort, like Heap sort, can accomplish this in O(nlogn) time. Sometimes, however, we
might be interested in only the largest value in the data set. We know we can find this in O(n) time. If we
needed to find the two(2) largest values, we might repeat the process, which would take O(2n) time or the
same O(n) overall. It follows that to find the k-largest values, it would take about O(kn) time. While that is still
O(n) it is possible to do a bit better. Specifically, we can use a heap to find the k largest values without the
need to sort the entire data set.
The program should read in a seed value, the number of values to generate, and the number of the
largest values to return, all as integers. Then, allocate the necessary space and then randomly generate
all the values requested.
Complete a function, ) to return the k-largest values in the array. You will need to use one or
more helper functions to maintain the heap property. Use a max-heap and return a list with the k-
maximum numbers in Descending order.
Ex: When the input is:
123,10,4
the output is:
Result:
950960938286819083736322
#include =0=0=0(0,1000000)0-1,000,000i=0ii++[i]=???[i]i=0iIn the cases where we are presented a large set of data, itis typical to sort the data to make searches easier. We know that a good sort, like Heap sort, can accomplish this inO(nlogn) time. Sometimes, however, we might be interested in only the largest value in the data set. We know we can find this inO(n) time. Ifwe needed to find the two(2) largest values, we might repeat the process, which would take O(2n) time or the same O(n) overall. It follows that to find the k-largest values, it would take about O(kn) time. While that is still O(n)itis possible todo a bit better. Specifically, we can use a heap to find the k largest values without the need to sort the entire data set.
The program should read in a seed value, the number of values to generate, and the number of the largest values to return, all as integers. Then, allocate the necessary space and then randomly generate all the values requested.
Complete a function, KMax()to return the k-largest values in the array. You will need to use one or more helper functions to maintain the heap property. Use a max-heap and return a list with the k-maximum numbers in Descending order.
Ex: When the input is:
123104
the output is:
Result:
950960938286819083736322
 Using C++!!5.7 LAB: Finding the k-max values In the cases where

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 Databases Questions!