12. Algorithms#
An algorithm is a step-by-step procedure for solving a problem. This chapter covers the two most fundamental algorithmic tasks — searching and sorting — and the mathematical framework used to compare their efficiency.
Why this chapter matters
Knowing an algorithm’s behavior under different inputs separates guessing from engineering:
linear search is simple but slow for large sorted data
binary search cuts the problem in half with every comparison
sorting algorithms trade simplicity for speed depending on input size
Big-O notation gives a hardware-independent language for comparing algorithms
Learning goals
By the end of this chapter, you should be able to:
implement and compare linear and binary search
trace through bubble, selection, and insertion sort
explain what O(N), O(N log N), and O(N²) mean
measure and interpret actual runtime performance