Module M12 · 12 of 35 in teaching order · Beginner
Searching
Linear and binary search and their relatives, with the preconditions each one needs.
Lessons
Linear search scans every element until it finds a match: the early exit, best, worst and average cost, the sentinel trick, and the built-ins in four languages.
How binary search finds a value in O(log n): low, mid and high, the loop invariant, duplicates and first occurrence, and the built-ins in C#, Python, Java and C++.
Three relatives of binary search on sorted data: jump search in O(√n), exponential search in O(log i), interpolation search and its O(n) worst case.
Topics this module covers
The full module scope. Topics without a lesson above are not written yet.
- linear
- iterative/recursive binary
- jump
- exponential
- interpolation
- comparison and preconditions