Homework

Homework

What to hand in

algo with a playlist command, passing go test ./..., plus a justified decision.

1. The crossover

For a move from position i to j, find when the list starts beating the array if you do not already hold the node.

Measure across combinations of i and j and fill in:

move array shifts list hops winner
47 → 3
500 → 499
99,000 → 50
your own

One sentence: is there a combination where the list wins without a held node?

2. The pointer cost in bytes

Work out how much memory a 100,000-item Playlist uses against a []Item — count Prev and Next at 8 bytes each, and the fact that every node is allocated separately.

Give the ratio. Tie it back to lesson 2's slice-header arithmetic.

3. Where the held node comes from

Step 3 showed the list winning by 24,000× when you already hold the node.

Describe how a program gets one. Specifically: what structure holds the title → *Node mapping, what it costs in memory, and what has to be updated on every insert.

(That is a description of lesson 10. Write it in your own words now — you will come back and compare.)

4. Singly versus doubly linked

What would you lose if Node had only Next?

Name every function in playlist.go that would break or get worse, and its new complexity. How much memory would you save?

5. The decision

One paragraph: for your playlist feature — array or linked list?

Justify it with the numbers from parts 1 and 2, not with generalities. If the answer is "array", that is a correct answer — say why.