Skip to content

Sorting

Régis Meyssonnier edited this page Apr 25, 2022 · 3 revisions

1. Merge Sort 🥇

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.

2. Sorting median 👍

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.

Data structure

  • 2 Sat
  • Compression
  • Tree

Clone this wiki locally