Question: Language is based on python 1. [total: 6] You are given an array A that contains n distinct numbers. The task is to compute another

Language is based on python 1. [total: 6] You are given anLanguage is based on python

1. [total: 6] You are given an array A that contains n distinct numbers. The task is to compute another array B such that for all j, we want B[j] to be the number of elements in A that appear after A[j] and are strictly smaller than A[j]. As an example, if you are given the input array A = [8, 10, 4, 7, 3, 5, 9, 1], then you want to output the array B = [5, 6, 2, 3, 1, 1, 1, 0]. This is because, in A, there are 5 elements that appear after A [0] = 8 and are smaller than 8 (i.e. 4, 7, 3, 5, 1), there are 6 elements that appear after A[1] = 10 and are smaller than 10 (i.e. 4, 7, 3, 5, 9, 1), etc. Design an algorithm to compute B given A as input. The worst case complexity of your algorithm must be O(n log n). This algorithm can be described in brief given what we have learned in class. Write a clear description of your algorithm (what data structure is used and how the algorithm utilizes the data structure) and justify its correctness and runtime. As usual, please use learned algorithms and analysis results from lectures and tutorials without repeating them

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!