| > 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) |
Applications operating on text would normally use a rope (aka cord) or gap buffer. A linked list would have horrible performance because random access within the text is important for most applications.
> (I'm building up GBs of data: so saving redundant chunks like this really wins)
You’re likely spending a huge amount of memory to store pointers between elements within the unshared chunks (8 or 16 extra bytes per element adds up in a hurry) so it may be worth investigating some “chunking” so that you only have to use pointers to link between chunks, which can be stored continuously.
Alternatively, consider whether the index representation used by suffix arrays will work for your use-case: https://en.wikipedia.org/wiki/Suffix_array