|
Why would one ever prefer a linked list over a dynamic array? I know about the asymptotic performance, but if you take actual memory performance into account (locality, cache, pointers are slow, etc), it seems dynamic arrays should be simpler and perform better. |
(Singly) linked lists are trivial to implement in an immutable way (the article talks about the difficulty of doubly-linked lists, implemented in a mutable way).
It's trivial to have linked lists share a tail; this makes datastructures like cactus stacks really easy.
Linked lists are amenable to reasoning by induction (e.g. in Coq, Agda, Idris, etc.).
Linked lists are amenable to lazy algorithms (e.g. iterators/generators).
Linked lists can be heavily optimised, e.g. using stream fusion.
That's off the top of my head. Note that in many cases it might be preferable to use linked lists in the source, but have them compiled to some other representation like arrays (or, in the case of fusion, a single tight loop).