Question: ( 2 0 points ) You are given a positive integer k and an array A [ 1 . . n ] that stores n
points You are given a positive integer and an array that
stores possibly nondistinct integer scores in the range The
scores in A are stored in nondecreasing order. The scores are conceptually
divided into groups such that for iin group i consists of scores in
the range Your task is to design an algorithm to
count the number of scores in group i and store the count in the array
The count for group i should be stored in the entry Your
algorithm cannot directly access for any jin or for any
iin Instead, it can only access andor modify A and using the
following three functions:
Init : It initializes all entries of to zero in time.
Compare : For jin it compares and and re
turns true if and belong to the same group, otherwise false.
This takes time.
Increase : For jin it finds the index of the group that
contains and adds to This function takes time.
Your task is to design an algorithm with the following running time re
quirements. Explain its correctness and analyze its running time. Note:
A correct answer to will get you all points, so you don't have to do
if you are certain about your answer to
points Design an algorithm that runs in time.
points Design an algorithm that runs in time.
Hint: Let be the size of group i for iin Subject to
dots the product is maximized when
for all iin
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
