Question: Using C + + ! ! 5 . 7 LAB: Finding the k - max values In the cases where we are presented a large
Using C LAB: Finding the kmax 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 time. Sometimes, however, we
might be interested in only the largest value in the data set. We know we can find this in time. If we
needed to find the two largest values, we might repeat the process, which would take time or the
same overall. It follows that to find the klargest values, it would take about time. While that is still
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 largest values in the array. You will need to use one or
more helper functions to maintain the heap property. Use a maxheap and return a list with the
maximum numbers in Descending order.
Ex: When the input is:
the output is:
Result:
#include iIn the cases where are presented a large set data, typical sort the data make searches easier. know that a good sort, like Heap sort, can accomplish this time. Sometimes, however, might interested only the largest value the data set. know can find this time. needed find the two largest values, might repeat the process, which would take time the same overall. follows that find the largest values, would take about time. While that still possible a bit better. Specifically, can use a heap find the largest values without the need sort the entire data set.
The program should read a seed value, the number values generate, and the number the largest values return, all integers. Then, allocate the necessary space and then randomly generate all the values requested.
Complete a function, return the largest values the array. You will need use one more helper functions maintain the heap property. Use a maxheap and return a list with the maximum numbers Descending order.
: When the input :
the output :
Result:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
