I'm currently creating a program to analyse the pathological cases of Quicksort. Namely, the transition of complexity from $O(n^2)$ to $O(n \log n)$ as a data set gets less ordered. Since Quicksort is a value-based algorithm, the choice of pivot determines its efficiency. We usually (Quicksort 3, and choosing a random element aside) select the first or last element as the pivot in an array. Therefore, since a good pivot is one that splits the array in half symmetrically, a more disordered array will make selecting a good pivot easier; or at least reduce the likely hood of running into the pathological case.
My program gradually randomises this array by swapping some elements each time. When I started to plot the graph of this using gnuplot I notice the trend I expected; a exponential distribution, branching off to a uniform distribution.
My question is, how do I quantify a level of disorder in a array? Is their a better way to gradually make an array of values more disordered?
Asked By : user103853
Answered By : rphv
Inversions are one way to measure "disorder" in a list:
Let $A[1..n]$ be an array of $n$ distinct numbers. If $i < j$ and $A[i] < A[j]$ then the pair $(i,j)$ is an inversion of $A$.
However, it's not the only such measure. In general, this concept is formalized in the notion of presortedness - roughly:
An integer function on a permutation $\sigma$ of a totally ordered set that reflects how much $\sigma$ differs from the total order.
The survey papers by Mannila [1] and Estivill-Castro & Wood [2] might be good places to start.
The question How to measure "sortedness" is related.
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/33082
0 comments:
Post a Comment
Let us know your responses and feedback