Open
Description
According to Computing and ranking measures of presortedness by J. Chen, the complexity of some of our measures of presortedness simply outrightly suck. With better algorithms, we could change them as follows, (quotes are from the paper):
- « Exc(X) is also linear computable (see , The Art of Computer Programming, Vol. 3: Sorting and Searching, Ex. 5.2.2-2) and we cannot do better. »
- « Altman and Chlebus [Sorting roughly sorted sequences in parallel] proved that Par(X) can be computed with O(n log Par(X)) comparisons », which means that Par(X) can be computed with a O(n log n) algorithm since 0 <= Par(X) <= n - 1.
- « Osc(X) can be computed in O(n log(Osc(X)/n)) time [Adaptive Sorting by O. Pertersson]. », which is roughly equivalent to O(n log n) considering that 0 <= Osc(X) <= (n * (n - 2) - 1) / 2. However Adaptive Sorting mentions that computing Osc(X) is an open problem, but that it is easy to compute it in O(n log n).
- Our implementation of Enc is O(n ²) while it could be reduced to O(n log n) by using a binary search during the construction of the encroaching lists.
- T. M. Chan and M. Pătraşcu give a O(n sqrt log n) algorithm to compite Inv(X) in Counting Inversions, Offline Orthogonal Range Counting, and Related Problems.
Also, some of the comments make me doubt the implementation of the of the measures of presortedness. Did I really understand every definition, or did I take some mental shortcuts? It's left to investigate... I'll gladly accept any help if anyone knows how to implement these algorithms with the complexities above.