Answered step by step
Verified Expert Solution
Question
1 Approved Answer
( 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 k and an array An that stores n possibly nondistinct integer scores in the range The scores in A are stored in nondecreasing order. The scores are conceptually divided into k groups such that for iink group i consists of scores in the range ikik Your task is to design an algorithm to count the number of scores in group i and store the count in the array Gk The count for group i should be stored in the entry Gi Your algorithm cannot directly access Aj for any jinn or Gi for any iink Instead, it can only access andor modify A and G using the following three functions: InitG : It initializes all entries of G to zero in Ok time. Compare rs : For ijinn it compares Ar and As and re turns true if Ar and As belong to the same group, otherwise false. This takes O time. Increasejx : For jinn it finds the index i of the group that contains Aj and adds x to Gi This function takes O 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 Oklogn time. points Design an algorithm that runs in Oklognk time. Hint: Let xi be the size of group i for iink Subject to xx dotsxkn the product xxcdotscdotsxn is maximized when xink for all iink
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started