I would like to generate data to test sorting algorithms with. This accomplishes two things:
- Find bugs. The output could easily be checked if it was in fact sorted correctly
- Profile the code and find which situations take longer for which parts.
I asked the question How do you test speed of sorting algorithm? awhile ago, but this question focuses particularly on generating the data.
I am thinking of
- sorted
- reverse sorted
- random
- sorted but then make
ninversions in randomly selected elements and see how changingnaffects the run time
Any suggestions? Do any frameworks exist that would make this easier? I'm thinking JUnit could be useful.
In this question on comp sci se an answer makes it sound like adding inversions and counting them doesn't mean much:
The number of inversions might work for some cases, but is sometimes insufficient. An example given in [3] is the sequence
$$\langle \lfloor n/2 \rfloor + 1, \lfloor n/2 \rfloor + 2, \ldots, n, 1, \ldots, \lfloor n/2 \rfloor \rangle$$
that has a quadratic number of inversions, but only consists of two ascending runs. It is nearly sorted, but this is not captured by inversions.
I'm not particularly strong in math and don't understand how the example illustrates what's wrong with counting the number of inversions? Is it just academic? How does it make sense to say "quadratic number of inversions"?