Python Tutorial · Revision notes
Python Searching & Sorting
Searching finds an item in a collection; sorting arranges items in order. Linear and binary search plus bubble, insertion, selection, merge and quick sort are the standard algorithms taught in every data-structures course and coding interview.
Quick revision
- Linear search O(n); binary search O(log n) but needs sorted data.
- Bubble, insertion, selection: O(n^2); insertion best O(n); selection fewest swaps.
- Merge sort: O(n log n) always, stable, O(n) space.
- Quick sort: average O(n log n), worst O(n^2), in-place, unstable.
- In practice use sorted() / list.sort() (Timsort).