3 ms·
People here dismiss the linear search, but for a small number of items (and yes, even thousands can be a small number), I wouldn't be so fast without testing it
by groestl 8y ago
People here dismiss the linear search, but for a small number of items (and yes, even thousands can be a small number), I wouldn't be so fast without testing it. Cache locality also has a say here, and depending on the exact circumstances, a linear search might make sense (even more so as a first version).
- gweinberg 8y agoI think the only time it makes sense to use a linear search is if you think the number of items on your list is low enough that it doesn't even matter what data structure you are using. But I would probably use a set rather than a list anyway if only because that more accurately reflects the nature of the data.
- lloeki 8y agoIIRC MySQL just skips using indices and does a linear search when a table size is small enough.
- machinecoffee 8y agoProbably a lot of DB Servers do that - which is why the plan for a query can change as the amount of data per table increases.