Well, I get hung up on difficulties all the time. There is an array of elements, for example A[n] . You need to find all the pairs so that A[i]>A[j] , as well as i < j .
So, if it's {10, 8, 6, 7, 11} , the pairs will be (10,8) (10, 6), (10,7) and so on...
I did a merge sort at nlogn time, and then binary search the entire array again in nlogn to get the indices of the elements in the sorted array.
So sortedArray={6 7 8 10 11} and index={3 2 0 1 4}
No matter what I try, I keep getting another n^2 time in complexity when I start comparing cycles. I mean, if I start the first element, i.e. 10, then it is equal to index[2] , which means that 2 elements less than it. Therefore, if index[2]<index[i] , then they can be accepted, but this increases complexity. Any thoughts? I don't need the code, just a hint in the right direction would be helpful.
Thanks. Everything I did in C and the complexity of the time is important here c
source share