both ends and works it way to the middle essentially every time value bigger than the pivot is found on the left side and value smaller than the pivot is found on the right sidethe two values are swapped once we reach the middle from both sidesthe pivot is swapped into place once the sequence is partitionedthe quicksort algorithm is called recursively on the two halves variables and are the indices of the left and right valuesrespectivelyduring the partitioning process if you look at the partition codethe two commented while loop conditions are probably easier to understand than the uncommented code howeverthe uncommented code only uses the less than operator quicksort is the sorting algorithm used by the sort method on lists it only requires that the less than operator be defined between items in the sequence by writing the two while loops as we havethe only required ordering is defined by the less than operator just as python requires the snapshot in fig shows the effect of partitioning on sequence in this figurethe sequence has been partitioned twice already the first partitioning picked pivot that was almost dead center howeverthe second partitioning picked pivot that was not so good the red line indicates the part of the sequence that is currently being partitioned see how the left-most value in that sub-sequence is the pivot value the two green dots are the pivot values that are already in their correct locations all values above the pivot will end up in the partition to the right of the pivot and all values to the left of the pivot are less than the pivot this is the nature of quicksort againby amortized complexity we can find that the quicksort algorithm runs in ( log ntime consider sorting the list [ using quicksort figure depicts the list after each call to the partition function the pivot in each call is identified by the orange colored item the partition function partitions the list extending to the right of its pivot after partitioningthe pivot is moved to its final location by swapping fig quicksort snapshot this copy belongs to 'acha