3 ms·
> You could have a header that differs from an internal one only on the last character and then you have to read the whole thing When people talk about BigO th
by vlovich123 2y ago
> You could have a header that differs from an internal one only on the last character and then you have to read the whole thing
When people talk about BigO they usually talk about average Big-o and worst/best case Big-o is explicitly called out if mentioned, so you can't just think in terms of the worst possible case. Regardless I think they made several mistakes here as you note correctly.
BTreeSet is log(N) in number of nodes compared. But for strings that comparison is O(L) since you at least have to compare it to the string you find. So I believe it's at best O(L log(N)) where L is the average string length and N is the number of nodes which is worse than the hash table which is just O(L). It's tricky though if most strings don't match your string. In that case I believe you end up degrading to an O(L) + O(log(N)).
Similarly, you are correct that they can't be logarithmic in size and must be linear since you have to store the data. Tries can be sublinear depending on the input since it's a form of compression as well.
Similarly you are right about trie complexity not being O(log(L)) for trie misses. I think what they're observing is a massive speedup because mismatches error out on the first character usually. But it wouldn't be logarithmic as there's unlikely to be a logarithmic relation between headers that mismatch and the universe of matching words.
- maciek12 2y agoThanks for replying, I really appreciate you taking the time to check my concerns! I was afraid I was going crazy haha. The part about big O being usually about the average case was helpful, I'm still at uni where we mostly talk about worst case performance.
- vlovich123 2y agoI'll note I could very well be wrong - very back of the paper first principles derivation and could easily have made a mistake. If you're in a relevant course, might be a good opportunity to flag this to a professor or TA as a way to review. These kind of analyses can be tricky sometimes, especially if you need to prove it vs just do an answer by feel which is how engineers end up doing it (vs CS students that take the proofs much more seriously). A way to sometimes double-check is to just simulate performance as input grows and see if it matches the expected log(N).