Let's review!
In this unit you learned to specify algorithms with preconditions, postconditions and loop invariants, and to measure them with run times, step counts and Big-O. You wrote linear and binary search and compared them, built subprograms to insert and delete array elements, wrote insertion sort and compared the sorts, processed 2-D arrays (including matrices and image pixels), designed recursive algorithms (factorial, fast power, numbers to words, fractals, XML, merge sort) and learned their pitfalls, and finished with formal test plans.
This review has a few questions from every lesson. Try each one on paper or in Python first, then press Show answer. Where a question shows code, type it in to check your prediction.
Check your understandingQuiz
1. Which pair is a precondition and a postcondition for binary search?
2. Which Big-O is the worst case of binary search?
3. Insertion sort on an already sorted list of n elements makes how many comparisons?
4. How many moves does deleting index 0 from an array of size n take, keeping the order?
5. After g = [[0] * 3 for r in range(2)] and g[1][2] = 5, what is g?
6. A is 2 × 4 and B is 4 × 3. What size is A × B?
7. What does factorial(0) return in the lesson's function, and why does it matter?
8. Why is naive recursive Fibonacci exponential?
9. What is the worst-case Big-O of merge sort?
10. What is regression testing?