Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hoare’s Quicksort algorithm chooses a random pivot. For reproducible results I'd suggest Scowen's modification which, among other things, chooses the middle item from the input. For this variant a sawtooth pattern with the pivot being the smallest appears to be the worst case input:</p> <pre><code>starting with { j i h g f a e d c b } compare 1 to 6 { (j) i h g f (a) e d c b } compare 6 to 10 { j i h g f (a) e d c (b) } compare 6 to 9 { j i h g f (a) e d (c) b } compare 6 to 8 { j i h g f (a) e (d) c b } compare 6 to 7 { j i h g f (a) (e) d c b } swap 1&lt;=&gt;6 { (a) i h g f (j) e d c b } compare 1 to 5 { (a) i h g (f) j e d c b } compare 1 to 4 { (a) i h (g) f j e d c b } compare 1 to 3 { (a) i (h) g f j e d c b } compare 1 to 2 { (a) (i) h g f j e d c b } compare 2 to 6 { a (i) h g f (j) e d c b } compare 3 to 6 { a i (h) g f (j) e d c b } compare 4 to 6 { a i h (g) f (j) e d c b } compare 5 to 6 { a i h g (f) (j) e d c b } compare and swap 6&lt;=&gt;10 { a i h g f (b) e d c (j) } compare 7 to 10 { a i h g f b (e) d c (j) } compare 8 to 10 { a i h g f b e (d) c (j) } compare 9 to 10 { a i h g f b e d (c) (j) } compare 2 to 6 { a (i) h g f (b) e d c j } compare 6 to 9 { a i h g f (b) e d (c) j } compare 6 to 8 { a i h g f (b) e (d) c j } compare 6 to 7 { a i h g f (b) (e) d c j } swap 2&lt;=&gt;6 { a (b) h g f (i) e d c j } compare 2 to 5 { a (b) h g (f) i e d c j } compare 2 to 4 { a (b) h (g) f i e d c j } compare 2 to 3 { a (b) (h) g f i e d c j } compare 3 to 6 { a b (h) g f (i) e d c j } compare 4 to 6 { a b h (g) f (i) e d c j } compare 5 to 6 { a b h g (f) (i) e d c j } compare and swap 6&lt;=&gt;9 { a b h g f (c) e d (i) j } compare 7 to 9 { a b h g f c (e) d (i) j } compare 8 to 9 { a b h g f c e (d) (i) j } compare 3 to 6 { a b (h) g f (c) e d i j } compare 6 to 8 { a b h g f (c) e (d) i j } compare 6 to 7 { a b h g f (c) (e) d i j } swap 3&lt;=&gt;6 { a b (c) g f (h) e d i j } compare 3 to 5 { a b (c) g (f) h e d i j } compare 3 to 4 { a b (c) (g) f h e d i j } compare 4 to 6 { a b c (g) f (h) e d i j } compare 5 to 6 { a b c g (f) (h) e d i j } compare and swap 6&lt;=&gt;8 { a b c g f (d) e (h) i j } compare 7 to 8 { a b c g f d (e) (h) i j } compare 4 to 6 { a b c (g) f (d) e h i j } compare 6 to 7 { a b c g f (d) (e) h i j } swap 4&lt;=&gt;6 { a b c (d) f (g) e h i j } compare 4 to 5 { a b c (d) (f) g e h i j } compare 5 to 6 { a b c d (f) (g) e h i j } compare and swap 6&lt;=&gt;7 { a b c d f (e) (g) h i j } compare and swap 5&lt;=&gt;6 { a b c d (e) (f) g h i j } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload