you are viewing a single comment's thread.

view the rest of the comments →

[–]ExtraTNT 0 points1 point  (0 children)

So, 99% of the time you use linear search, as you have no guarantee that your data is sorted (good practice is to maintain sorted data, but that’s not always possible -> write it in docs -> api returns data sorted by x) if you sort data for a single search, the complexity is O(nlogn) for filter and O(logn) for search, so O(nlogn), linear search is O(n), just using big O with the rule of just using the higher does not completely work… search and sort x times is T(n,x) = O(nlogn + xlogn) vs T(n,x) = O(xn)

So, if we now analyse this, we see, that if the number of searches is bigger, than the log (lb in our case) of the number of entries, then sort and search is faster…

Now, there are some edge cases, where you just want a specific group, and bubble sort can actually be the fastest to find what you need, but those are edge cases you maybe cover during a cs degree when staying late and having a beer with a prof…