An algorithm escapes from most bad cases using a randomized pivot,
excluding continuous elements equals to a pivot from partitioning,
and asymmetric search.
It searches forward an element greater or equals to a pivot,
and searches backward an element less than a pivot.
I thank MichaelT, Asymmetric search is devised to resolve [2,1,2,1,2,1,2,1].
The following result is generated by my function qsort_random(). N = 100,000
usec call compare copy pattern
80132 62946 1971278 877143 random
47326 57578 1606067 215155 sorted : 0,1,2,3,...,n-1
49927 63578 1628883 338715 sorted in reverse : n-1,n-2,...,2,1,0
55619 63781 1596934 377330 nearly reverse : n-2,n-1,n-4,n-3,...,2,3,0,1
54714 66667 1611454 290392 median-3-killer : n-1,0,1,2,...,n-2
1491 1 99999 4 all values the same : n,n,n,...
1577 1 99999 4 first is higher : n,1,1,1,...
2778 2 156159 10 last is lower : n,n,n,...,n,1
2994 3 199996 100009 a few data : n,...,n,1,...,1
3196 3 199996 50012 zigzag : n,1,n,1,...,n,1
917796 56284 67721985 673356 valley(sawtooth?) : n-1,n-3,...,0,...,n-4,n-2
Most cases are faster than a random pattern.
Valley pattern is a bad case for most pivot selection.
qsort(3) usec = 14523 call = 0 compare = 884463 copy = 0
qsort_head() usec = 138609 call = 99999 compare = 8120991 copy = 1214397
qsort_middle() usec = 664325 call = 99999 compare = 52928111 copy = 1036047
qsort_trad() usec = 118122 call = 99999 compare = 6476025 copy = 1337523
qsort_random() usec = 295699 call = 58806 compare = 19439952 copy = 732962
qsort_log2() usec = 66411 call = 63987 compare = 1597455 copy = 944821
qsort_log2() escapes from bad case by selecting a pivot in log2(N) elements.
qsort(3) use GNU library which is a merge sort of index sorting.
qsort_trad() select a pivot in first, middle and last elements.
qsort_random() and qsort_log2() don't use swapping.
Source C programs and scripts are posted in github.
[2,1,2,1,2,1,2,1]and that being the entire answer). The goal of the question would, ideally, be one where other people can come and find out more about the why (which has an answer) rather than examples (of which there are countless).