Skip to main content
added 61 characters in body
Source Link
Student
  • 101
  • 2

I'm looking up the complexities of sorting algorithms. There can be performance harm when the array is already presorted when running certain algorithms. E.g. Using last element as pivot in quick sort would harm the performance when the array has already been pre-sorted. However, when I attempt to cross check with other sources for ways to walk around it, it seems there's no source suggesting putting in place a check to see if the array has already been sorted is one way to walk around, despite the simplicity of this solution.

So I wonder is it practically feasible? If so, why people are not implementing this on every sorting algorithms just before they begin to check if the array has already been presorted before the sorting algorithm executes? Especially when such checking only involve O(n) time at max.

I'm looking up the complexities of sorting algorithms. There can be performance harm when the array is already presorted when running certain algorithms. E.g. Using last element as pivot in quick sort would harm the performance when the array has already been pre-sorted. However, when I attempt to cross check with other sources for ways to walk around it, it seems there's no source suggesting putting in place a check to see if the array has already been sorted is one way to walk around, despite the simplicity of this solution.

So I wonder is it practically feasible? If so, why people are not implementing this on every sorting algorithms just before they begin to check if the array has already been presorted before the sorting algorithm executes?

I'm looking up the complexities of sorting algorithms. There can be performance harm when the array is already presorted when running certain algorithms. E.g. Using last element as pivot in quick sort would harm the performance when the array has already been pre-sorted. However, when I attempt to cross check with other sources for ways to walk around it, it seems there's no source suggesting putting in place a check to see if the array has already been sorted is one way to walk around, despite the simplicity of this solution.

So I wonder is it practically feasible? If so, why people are not implementing this on every sorting algorithms just before they begin to check if the array has already been presorted before the sorting algorithm executes? Especially when such checking only involve O(n) time at max.

Source Link
Student
  • 101
  • 2

Sorting optimization to presorted array

I'm looking up the complexities of sorting algorithms. There can be performance harm when the array is already presorted when running certain algorithms. E.g. Using last element as pivot in quick sort would harm the performance when the array has already been pre-sorted. However, when I attempt to cross check with other sources for ways to walk around it, it seems there's no source suggesting putting in place a check to see if the array has already been sorted is one way to walk around, despite the simplicity of this solution.

So I wonder is it practically feasible? If so, why people are not implementing this on every sorting algorithms just before they begin to check if the array has already been presorted before the sorting algorithm executes?