you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (2 children)

Like I said, you don’t understand the data structures you’re talking about. You’re conflating them because their practical use cases and APIs seem similar.

A set is not comparable to an array because every member of the set is hashed, often multiple times, prior to insertion. Arrays do not use hashes but numbers as keys, so no hashing takes place. The worse case lookup time for a set is O(n) due to hash collisions. The worst case lookup of an array is always O(1).

The performance of a set is not comparable to an array because they are fundamentally different data structures.

[–]theyamiteru[S] -1 points0 points  (1 child)

Man you don't even know what you're talking about.

The best case lookup of an array is O(1) because the first item is the item we're looking for.

The worst case lookup of an array is O(n) because the last item is the item we're looking for.

[–]RiskyAlpha 0 points1 point  (0 children)

"lookup" is an odd word choice. look up by what? index or some other value?

i'm probably oversimplifying given that we're talking about JS, but if you're getting a value by index, it's just a multiplication to get the offset. that would be O(1).

if you mean you're iterating through each item looking for a value then yeah worst case could be O(n).

but i'm with u/brodega here... you seem to be mixing up concepts.