Sorting in Python

Written by    15:32 February 28, 2016 

Simple implementation of five common sorting  algorithm in Python.

Bubble Sort

Bubble_sort_animation

 

Best/Worst/Average Time Complexity:\(O(n^{2})/O(n^{2})/O(n^{2})\)

Memory Complexity: \(O(n)\)

Selection Sort

250px-Selection_sort_animation

Best/Worst/Average Time Complexity: \(O(n^{2})/O(n^{2})/O(n^{2})\)

Memory Complexity: \(O(n)\)

Insertion Sort

Insertion_sort

Best/Worst/Average Time Complexity: \(O(n)/O(n^{2})/O(n^{2})\)

Memory Complexity: \(O(n)\)

Quick Sort

Sorting_quicksort_anim

Best/Worst/Average Time Complexity: \(O(n\log {(n)})/O(n^{2})/O(n\log {(n)})\)

Worst/Average Memory Complexity: Not Sure

Heap Sort

Sorting_heapsort_anim

Best/Worst/Average Time Complexity: \(O(n\log {(n)})/O(n\log {(n)})/O(n\log {(n)})\)

Memory Complexity: \(O(n)\)

References

https://en.wikipedia.org/wiki/Bubble_sort

https://en.wikipedia.org/wiki/Selection_sort

https://en.wikipedia.org/wiki/Insertion_sort

https://en.wikipedia.org/wiki/Quicksort

https://en.wikipedia.org/wiki/Heapsort