-
Notifications
You must be signed in to change notification settings - Fork 0
Sorting
Régis Meyssonnier edited this page Apr 25, 2022
·
3 revisions
This an example how the merge sort works, and count the inversion make by the algorithm.
In inversion is a swap when 2 elements with indice i and j (i < j) and when array[i] > array[j] in the array who store the data.
This file sort an array and find a median between an interval and continue until the end of the array.
For the array [20, 10, 30, 40, 50] and d = 3 the common ratio.
You find the median of the 3 first element 20 10 30, sort them with the hashmap who counts the frequency of the number,
and search the median 20. Compare with the value 40 out of the interval if the median is 2 times better than the
value 40(40 >= 20 x 2) and count it. Repeat this processus until the end.