The chapter in short
Computational thinking breaks problems into parts, finds patterns, abstracts away detail and designs algorithms. The chapter applies these skills to designing and analysing algorithms.
It covers algorithm design strategies, recursion, searching and sorting, and measuring efficiency with Big-O notation.
Computational thinkingRecursionBase caseDivide and conquerBig-O notation
Key points
- Computational thinking: decomposition, pattern recognition, abstraction and algorithm design.
- Recursion solves a problem by calling itself on a smaller case, with a base case to stop.
- Merge sort and quick sort divide and conquer; they are faster than bubble sort on large lists.
- Binary search needs sorted data and runs in O(log n).
- Big-O describes worst-case growth of running time.
- Choosing the right algorithm matters more than faster hardware for large inputs.
Definitions
- 1
Computational thinking
A problem-solving method using decomposition, patterns, abstraction and algorithms.
- 2
Recursion
A function calling itself to solve smaller instances of a problem.
- 3
Base case
The condition that ends recursion.
- 4
Divide and conquer
Solving a problem by splitting it into smaller subproblems.
- 5
Big-O notation
A way of describing how an algorithm's running time grows.
Formulas
Recursive factorial
def fact(n): return 1 if n == 0 else n * fact(n - 1)