in reply to Reaped: Accidental dup; please delete.
in thread [OT] The interesting problem of comparing bit-strings.
With lists, step 2, is cheaper, but you still have to find the insertion point in the list which is O(N), so globally, the operation remains O(N).
Lists are cache unfriendly by two reasons: 1) they use more memory than arrays (for built-in types at least x2, but x4 or x8 commonly) and 2) they may be scattered in memory and turn the cache prefetching useless. So it is easy to get into a situation where advancing to the next element requires always going to L3 or even RAM.
In contrast, navigating an array, even when it doesn't fit into L2, is much faster because the cache prefetching is fully effective.
BTW, You get O(logN) insertions when you use a tree.
|
|---|