What are the differences in efficiencies between set and array for operations?
Examples:
In Ruby, Set
is written using an underlying Hash
for its storage, and it should generally perform equivalent to a Hash. Thus:
include?
: O(1) for Set, O(n) for Arraydelete
: O(1) for Set, O(n) for Array...etc.
If by "lookups" you mean looking up by index, I'd note that the default Set implementation is unordered, so it doesn't support that operation in the same way an Array does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With