Python Quicksort using Hoare Partitioning and No Recursion

preview_player
Показать описание
In place quicksort algorithm walkthrough for practicing python.

Chapters
0:36 Hoare partitioning
2:27 Optimizations
Рекомендации по теме
Комментарии
Автор

Input: [6, 100, 5, 7, 9]
Output: [5, 100, 6, 7, 9]

There seems to be an issue when i and j pointers are both at a number that should be part of the right side of the partition but that number is not evaluated because `i < j` is false.
In this case, i stops at 6(index=0) because 6 is greater than the pivot and j stops at 5(index=2) because 5 equals the pivot.
After the swap takes place, i is incremented and j is decremented. i and j are now equal at index 1. With quicksort(array, low, j), indices 0 through 1 inclusively is the left side of the partition. With quicksort(array, j+1, hi), indices 2 to 4 inclusively are right side of the partition. 100(index=1) should be on the right side of the partition.

ThePelcher
welcome to shbcf.ru