I am not able to understand how x and y are counting inversion and how they are sorting for x and y in inversion function as there is no condition return in it
Inversion count
hi @anuragavm123 x and y are counted by the recursive calls on the smaller subarrays.
As for the sorting part, we are not explicity sorting the array, but we are calling the “merge” function which will perform the sorting on the part it is called on (by merge sort)
Ma’am but as we are calling x and y by recursion then how x and y are getting values that how many pairs they can form . X and y are only increasing in recursion they are not forming pairs for counting Paris and it don’t have any checking condition for x and y
@anuragavm123 why do we need a condition for x and y? Sir has explained in the video that we sort after counting the inversions, so sorting will not disturb the first answer.
I’d suggest you to dry run the code once, then you’ll be able to grasp how the answer for x and y is being calculated.
Ma’am i understood sorting part but still after seen video again and doing dry run i am not able to understand that how x and y is getting values because for getting value in x it should compair with different elements of first half array but there is no such condition .
@anuragavm123 we are not calculating x like it is explained in the video. The implementation is a bit different. We call the smaller subproblems for x and y and recursion solves it for you. This is why i suggested dry running the code.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.