3 ms·
>One case that seems to make sense is any time you want to do constant-time pops/appends… maybe? Yes, and constant time insertions/deletions in the middle of t
by MontyCarloHall 4y ago
>One case that seems to make sense is any time you want to do constant-time pops/appends… maybe?
Yes, and constant time insertions/deletions in the middle of the list, assuming you know the address ahead of time.
This makes them great as backing queues in an LRU cache: given some key/value pairs, have a linked list whose nodes map to each key. Additions to the K/V store gets appended to the LL. This lets you easily remove the oldest n elements in the K/V store, by traversing from the head of the LL. It also lets you efficiently remove arbitrary elements from the K/V store, if you store the addresses of each LL node as values in the K/V, since deletions in the middle of the LL are constant time.
>yet I see them employed in various places all the time
I agree, however, that most LL applications (like the one I just mentioned) are fairly niche. LLs are overused because they’re dead simple to implement and commonly taught in intro CS classes.