Homework
What to hand in
A working algo project with gen and find, passing go test ./..., plus a
one-page measurement report.
1. Pick your theme and adapt Item
Music, film, games or books. Rename Artist to whatever fits (Director,
Studio, Author) and adapt the generator.
Keep Year and Rating bounded. You may change the bounds — 1970–2030 makes
more sense for games — but they have to stay.
2. Measure the growth curve
Generate libraries of 1,000, 10,000, 100,000 and 1,000,000 items
with the same -seed. For each, measure a worst-case search (look for a title
that is not there) and fill in the table:
| n | comparisons | comparisons ÷ n |
|---|---|---|
| 1,000 | ||
| 10,000 | ||
| 100,000 | ||
| 1,000,000 |
The last column must be constant. Explain in one sentence why.
3. Where the clock stops lying
Measure the same thing with a clock (time.Since). Find the smallest n for
which your machine reports something other than zero.
Write down that n and your CPU. Compare with a classmate — the numbers will differ, and the comparison counts will not. That is this entire lesson in one sentence.
4. A prediction
Without measuring, write down how many comparisons a worst-case search will cost at n = 5,000,000. Then measure it.
If you were wrong, the mistake was not arithmetic — something about O(n) is not yet clear. Write down what.
5. When O(n) is enough
One paragraph: when is linear search the right choice, despite everything faster that exists? Give a concrete example with numbers.
(Hint: in lesson 6 you will see linear search beat binary search — and not because anybody made a mistake.)