Question: Problem 4. You are given an array A[1 : n] which includes the scores of n players in a game. They are ranked in the

 Problem 4. You are given an array A[1 : n] which

Problem 4. You are given an array A[1 : n] which includes the scores of n players in a game. They are ranked in the following way: Rank of a player is an integer r if there are exactly r 1 distinct scores strictly smaller than the score of this player (irrespective of the number of players). (a) Design and analyze an algorithm that given the array A, can find the rank of all players in the array in O(n log n) time. (15 points) Example. Suppose the input array is A = [1, 7, 6, 5, 2, 4, 5, 2] for 8 players; then the rank of players is: Player A[1] has rank 1 (as A[1] = 1 is the smallest number); Player A[2] has rank 6 (as A[2] = 7 has 5 distinct smaller numbers: {1,6,5,4, 2}); Player A[3] has rank 5 (as A[3] = 6 has 4 distinct smaller numbers: {1,5,4, 2}); Player A[4] has rank 4 (as A[4] = 5 has 3 distinct smaller numbers: {1, 4, 2}); Player A[5] has rank 2 (as A[5] = 2 has 1 distinct smaller number: {1}); Player A[6] has rank 3 (as A[6] = 4 has 2 distinct smaller numbers: {1, 2}); Player A[7] has rank 4 (as A[7] = 5 has 3 distinct smaller numbers: {1, 4,2}); Player A[8] has rank 2 (as A[8] = 2 has 1 distinct smaller number: {1})

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!