|
|
|
|
|
by alexhutcheson
1923 days ago
|
|
Sorted linked lists are also especially-not-useful, because you can’t binary search them, which is often the main benefit to having something sorted. The only thing a sorted linked list is really good for is being able to cheaply peek/pop the lowest- or highest-valued item, and a heap is almost always better for that use-case in practice. |
|
Or cheaply peek/pop the middle items, and reinsert a middle item. As is the most common operation in Knuth's solution to the exact cover problem (aka: Dancing Links / Algorithm X)
There's also benefits to middle-operations, such as text editing (although text files are so small that inefficient operations aren't a big deal anymore).
----------
Linked Lists also can be "merged" together, in a sort of "inverse tree" sort of way.
Consider the following data: "ABCDEFG", "123ABCDEFG", and "111ABCDEFG".
The two array representations are obvious. But Linked-Lists can optimize that into:
* A -> B -> C -> D -> E -> F -> G
* 1 -> 1 -> 1 -> A ...
* 1 -> 2 -> 3 -> A ...
This has come up a lot for me in a recent toy problem I've been working on. A lot of sub-lists happen to be have the same "ending" as other lists, so I'm merging the linked lists and saving precious RAM (I'm building up GBs of data: so saving redundant chunks like this really wins)