โ Computer Science Fundamentals learning pathComputer Science Fundamentals ยท Module 3 of 10
Algorithms and Big-O
An algorithm is a step-by-step method; Big-O describes how its cost grows.
๐ Key ideas
- Algorithms take input and produce output in a finite number of steps.
- Big-O describes growth: O(1), O(log n), O(n), O(n log n), O(nยฒ).
- Linear search is O(n); binary search on sorted data is O(log n).
- Nested loops over the same data are often O(nยฒ).
- Space complexity measures extra memory used.
๐ก Real-life example: Like finding a word in a dictionary: flipping page by page is O(n), opening in the middle and halving is O(log n).
AlgorithmStep-by-step method to solve a problem
Big-OHow cost grows with input size
O(log n)Grows slowly by halving
Space complexityExtra memory an algorithm needs