Relative Content

Tag Archive for pythonpython-3.xalgorithmsortingquicksort

Quick Sort Implementation Python – Understanding Base Cases

I’ve been trying to understand quick sort by implementing it myself in Python using the left and right pointer method. I can’t seem to get it to work and looking at visualizations online, I’m failing to understand how quicksort works when operating on a list of length 2. According to most sources I’ve read, you should select a pivot and your left and right pointers should not include that pivot value when moving left/right. When a list is of length 2, you select a pivot and are left with a list of length 1 and left/right immediately meet. How would quicksort ever sort the input [5,4]?