Fruit flies of algorithm analysis
Min (or max) selection sort
Simple insertion sort
Bubble sort
Quicksort
Heapsort
Mergesort
Bucket sort
Radix sort
Use selection sort for very fast programming, but
only for a relatively small number of elements.
O(N2)
In-place
(Insertion or bubble sort are equivalent.)
Note:
We discuss sorting as if we were just sorting numbers.
Often the numbers are just a part (called the "key") of a more complex object or "record".
- Divide & Conquer
(cleave rather than whittle)
- Data Structuring
(tree rather than list)
- "Digital" Representations
exploit linear addressing princ.
Use when applicable:
Small range of integer values (or equivalent).
O(N) time to sort N items
Extra space is required ("buckets")
An alternated to bucket sort for larger (but not too large) range of integers.
Effectively a multi-pass bucket sort
O(N) time
Extra space is required
Prototypical divide & conquer
In-place (no extra space)
O(N logN) "average" time
O(N2) worst case time
O(N logN) "best" case
O(N2) worst case
O(N logN) without qualification
In-Place
Use tree to great advantage
Non-recursive
Based on "Peter Principle"
Typical memory layout
Typical Heap State
Calls to new find free space large enough.
C++: delete releases space
Java: space released when not accessible