Homework

Homework

What to hand in

algo with sweep and std, passing go test ./..., plus a report on your own crossover.

1. Your crossover

Run algo sweep in all three configurations and fill in:

configuration your crossover
-ints contiguous
-ints -scattered
strings, contiguous

Compare with this lesson's (≈6, ≈6, ≈3) and with transit's (≈50 and >127).

If your numbers differ, that is a result, not a mistake. Explain which of the three mechanisms best accounts for the difference in your case.

2. Your processor

State your CPU model and its L1 cache size.

Work out how many int32 values fit in your L1. Relate that number to the n at which binary starts winning clearly in your table.

3. Where the limit bites

At what n does linear search become unacceptable for your library, if a search has to fit inside 16 ms (one frame at 60 Hz)?

Use your own lin ns/op figures. Give the n.

4. The cost of the precondition

Binary search needs sorted data. You have not written a sort yet — but sort.Slice exists.

Measure: what does one sort of 100,000 items cost, and how many binary searches must you perform before that sort pays for itself against linear search?

That number is lesson 7's motivation.

5. The decision

One paragraph: for your library's search-by-title — linear, hand-rolled binary, or sort.Search?

State your n, your crossover, and how often the library changes. If it changes after every search, the answer may be "linear" — and that will be correct.