News for hackers. Stuff that matters.
Re:In Defense of Linked Lists by GuB-42 on Friday November 04, 2022 @08:56PM (#33476445)
> Often even for things that require lookup (i.e. vector outperforming a set)

I am always uncomfortable using higher algorithmic complexity. Sure, for small data sets, the vector will outperform the set, but it may not stay small forever. I may waste a millisecond now, but at least, I won't waste an hour if the user decides to use 100x the amount of data I initially considered. And using much more data than expected is a very common thing. It is a robustness thing more than optimization.

If you want both, there are staged algorithms, a typical example is a sort algorithm that goes insertion -> quicksort -> mergesort. Insertion sort is O(N^2), but it is great for small arrays, quicksort is O(N log N) on average but may become O(N^2) in some cases, and mergesort is guaranteed O(N log N) and parallelizable, but it is also the slowest for small arrays. For lists, that would be a list of vectors.

Re:In Defense of Linked Lists by jll29 on Friday November 04, 2022 @10:22PM (#33477144)
I like the staging idea, but curiously I haven't seen any papers investigating this.

Obviously, there is an overhead cost of the staging itself, which hits the use case for small data, and there is the question "From what data size onwards to use what algorithm?".

For example, I just had a look at sort in Clang's STL implementation, which seems to set a boundary at N=1000. Since the number is a multiple of 10, it looks like it might be arbitrarily picked, in any case there is no paper references in the comments to back it up.

Are people aware of formal studies that explore whether it is worth the trouble to inspect data structure and then to dispatch to different algorithms based on the findings?

Re:In Defense of Linked Lists by the_sleaze_ on Friday November 04, 2022 @10:59PM (#33477370)
You're saying you think there's still optimization to be done re. the N=1000 constant?

Other than that, I'd suggest that big O complexity is already telling you that the inspection is worth it. Assuming inspection of an array is constant.

Re:In Defense of Linked Lists by BeetleB on Saturday November 05, 2022 @01:48PM (#33483766)
> Sure, for small data sets, the vector will outperform the set, but it may not stay small forever.

In over 90% of SW applications written in C++, there is little to no uncertainty on the size of the data set. Most applications are written for a very specific purpose, with fairly well known needs.

If my data set is size N, and I can benchmark and show the vector outperforms the theoretical option up to, say, 20N, it's a safe choice to go with vector. Doing these analyses is engineering.

In any case, it's almost trivial to swap out the vector with other options when needed, if you plan for it.