A curious case of O(N^2) behavior which should be O(N) (2023)
21–30 of 46 posts
Re: A curious case of O(N^2) behavior which should be O(N) (2023)
#22Ah yes, the most reliable solution to a wrong choice of a data structure: add data-specific hacks until it works. For the life of me I can't figure out why people never consider replacing linked lists. Even without worst-case O(n) insertion, they usually behave worse than vectors, deques, or hives.
Re: A curious case of O(N^2) behavior which should be O(N) (2023)
#23Re: A curious case of O(N^2) behavior which should be O(N) (2023)
#24Re: A curious case of O(N^2) behavior which should be O(N) (2023)
#25Ah yes, the most reliable solution to a wrong choice of a data structure: add data-specific hacks until it works. For the life of me I can't figure out why people never consider replacing linked lists. Even without worst-case O(n) insertion, they usually behave worse than vectors, deques, or hives.
Re: A curious case of O(N^2) behavior which should be O(N) (2023)
#26Earlier quoted context omitted.
A classic. Every time I see that link I read the whole thing starting from the new beginning. ...oops
I opened the link and just started reading. I have a really dumb question that may expose common knowledge I don’t have, about this quote: > The total amount of space needed to represent this collection of strings is O(k n^2). I haven’t seen O-notation ever represent ram usage, just algorithm complexity. Is this common?
Very. For instance if you look at sorting algorithms on wikipedia they pretty much all list performance (best, worst, average) but also worst-case space complexity, in O notation.
Re: A curious case of O(N^2) behavior which should be O(N) (2023)
#27Why was the solution not to get rid of the linked list and replace it with a red/black tree?
Re: A curious case of O(N^2) behavior which should be O(N) (2023)
#28Why was the solution not to get rid of the linked list and replace it with a red/black tree?
Or hash table, or any other kind of tree. My guess would be because it was implemented in c, where the usual practice if you need a container type other than a fixed size array is to implement it yourself. IME, c code tends to use linked lists for a lot of things that in most other languages would be implemented using a better suited, and more performent, container type from the standard library. One way that other l…
I guess a flat array could still be debatable if you're usually inserting near but not at the end, as it'll still need to move all the following elements. But it seems dubious.
Re: A curious case of O(N^2) behavior which should be O(N) (2023)
#291. Does this have to be sorted?
2. Why is it sorted alphabetically instead of naturally?
Re: A curious case of O(N^2) behavior which should be O(N) (2023)
#30Ah yes, the most reliable solution to a wrong choice of a data structure: add data-specific hacks until it works. For the life of me I can't figure out why people never consider replacing linked lists. Even without worst-case O(n) insertion, they usually behave worse than vectors, deques, or hives.
What is a hive in the context of data structures?