Skip to main content
Tweeted twitter.com/#!/StackProgrammer/status/514889524489371648
Modify question focus to be the conditions for when quicksort does badly rather than examples.
Source Link
user40980
user40980

Example arrays where quicksort would do badly What makes for a bad case for quick sort?

I am learning about quicksort and want to illustrate different arrays that quicksort would have a hard time on. The quicksort I have in mind does not have an initial random shuffling, does 2 partition, and does not compute the median.

I thought up of three examples so far:

[1,2,3,4,5,6,7,8,9,10] - when the array is sorted
[10,9,8,7,6,5,4,3,2,1] - when the array is reversed
[1,1,1,1,1,1,1,1,1,1] - when the array is the same values
[1,1,1,2,2,2,3,3,3,3] - when there are few and unique keys

Are there any more examples you can think of? ForFor instance, I'm not too sure about this one:

[1,3,5,7,9,10,8,6,4,2]

So what makes for an array that quicksort has difficulty with compared to one where it is (nearly) ideal?

Example arrays where quicksort would do badly

I am learning about quicksort and want to illustrate different arrays that quicksort would have a hard time on. The quicksort I have in mind does not have an initial random shuffling, does 2 partition, and does not compute the median.

I thought up of three examples so far:

[1,2,3,4,5,6,7,8,9,10] - when the array is sorted
[10,9,8,7,6,5,4,3,2,1] - when the array is reversed
[1,1,1,1,1,1,1,1,1,1] - when the array is the same values
[1,1,1,2,2,2,3,3,3,3] - when there are few and unique keys

Are there any more examples you can think of? For instance, I'm not too sure about this one:

[1,3,5,7,9,10,8,6,4,2]

What makes for a bad case for quick sort?

I am learning about quicksort and want to illustrate different arrays that quicksort would have a hard time on. The quicksort I have in mind does not have an initial random shuffling, does 2 partition, and does not compute the median.

I thought up of three examples so far:

[1,2,3,4,5,6,7,8,9,10] - when the array is sorted
[10,9,8,7,6,5,4,3,2,1] - when the array is reversed
[1,1,1,1,1,1,1,1,1,1] - when the array is the same values
[1,1,1,2,2,2,3,3,3,3] - when there are few and unique keys

For instance, I'm not too sure about this one:

[1,3,5,7,9,10,8,6,4,2]

So what makes for an array that quicksort has difficulty with compared to one where it is (nearly) ideal?

Source Link
mrQWERTY
  • 243
  • 1
  • 3
  • 6

Example arrays where quicksort would do badly

I am learning about quicksort and want to illustrate different arrays that quicksort would have a hard time on. The quicksort I have in mind does not have an initial random shuffling, does 2 partition, and does not compute the median.

I thought up of three examples so far:

[1,2,3,4,5,6,7,8,9,10] - when the array is sorted
[10,9,8,7,6,5,4,3,2,1] - when the array is reversed
[1,1,1,1,1,1,1,1,1,1] - when the array is the same values
[1,1,1,2,2,2,3,3,3,3] - when there are few and unique keys

Are there any more examples you can think of? For instance, I'm not too sure about this one:

[1,3,5,7,9,10,8,6,4,2]