Advertisement
Rick10101221

Naive vs Lomuto vs Hoare Quicksort Partition

Jul 18th, 2022 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. Naive
  2. - Stable
  3. - Requires 3 traversals
  4.  
  5. Lomuto
  6. - Unstable
  7. - In-place
  8. - Faster than Naive
  9. - Slower for larger data sets >100000. This is because the Naive solution does not swap elements in-place. Lomuto's memory reduction naturally leads to cases where larger runtimes are expected.
  10.  
  11. Hoare
  12. - Unstable
  13. - In-place
  14. - Faster than Lomuto
  15. - Used in practice
  16.  
  17. Note stable algorithms retain the original order of equal elements in the output array
  18. Ex: Sort [[1,5], [1,2], [5,4], [3,4], [7,9]] on first key
  19. A stable sorting algorithm will sort the list as: [[1,5], [1,2], [3,4], [5,4], [7,9]]
  20. While an unstable sorting algorithm MAY sort the list as: [[1,2], [1,5], [3,4], [5,4], [7,9]]
  21.  
  22. Sources
  23. - https://www.geeksforgeeks.org/quick-sort/
  24. - https://www.geeksforgeeks.org/hoares-vs-lomuto-partition-scheme-quicksort/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement