Algorithms: Quicksort
Why Stack Overflow recommends it
Stack Overflow users link it as a reference for how quicksort partitioning works, both when debugging in-place implementations and when discussing how the pivot is handled.
Recommended by 0 people across 0 different months, 2018 to 2019.
What it is
A short HackerRank tutorial that walks through the basics of quicksort: choosing a pivot, partitioning an array, and recursing on the two sides. It is presented by Gayle Laakmann McDowell as part of HackerRank's Cracking the Coding Interview series.
What people said
Cites Nicola Pedretti · 2018-08 · Stack Overflow · on “Quicksort algorithm -- clarification”
I have been looking at different videos and read different articles on the quicksort algorithm. I understand how it works and if I didn't there is plenty of material online for me to look into. The problem I am having here is that some of the articles I found state the following ( from wikipedia [LINK] ) : Reorder the array so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the partition operation. some other sources, ( hackerrank video [this video] ): We swap elements around such that all element
Cites rcgldr · 2019-03 · Stack Overflow · on “Why does quicksort exclude the middle element but mergesort includes it?”
Note this depends on the partition algorithm. Lomuto [LINK] excludes the pivot, while Hoare [LINK] includes the pivot in one of the partitions. A variation of Hoare - youtube [this video] , doesn't move the pivot or any values equal to the pivot value.
Cites wise_gremlin · 2019-08 · Stack Overflow · on “Quick Sort Algorithm in Ruby - Stack Level Too Deep”
I am trying to implement a quick sort algorithm in Ruby. I got a simple one working pretty quickly but it involved creating temporary arrays on the fly. I'm trying to implement a more streamlined quick sort that only swaps elements in place without the need to create additional arrays. Does anyone know why this code doesn't work? I've been following the pattern laid out here [this video] in exact detail but I can't get it to work properly. def quicksort(arr = [], left = 0, right = 0) right = arr.length - 1 if right < 1 if left < right index = partition(arr, left, right) quicksort(arr, left, index - 1) quicksort(arr, index, right) end arr end def partition(arr, left, right) pivot = arr[(left + rig
Critical rcgldr · 2018-11 · Stack Overflow · on “Quick Sort with first element as pivot”
The pivot is not always moved into it's sorted position. The quicksort algorithm used in this video [this video] only moves numbers smaller than the pivot to the left of numbers greater than the pivot, and ignores numbers equal to the pivot, including the pivot itself.