Set has contains function which returns true if member exists in the set; otherwise, false.
and its complexity is O(1).
I want to know how its complexity is constant O(1) i.e. it does not depends on size
Here are the docs : https://developer.apple.com/documentation/swift/set/1540013-contains
It will use hash function to insert, search. Good hash function will lead to 0(1) time complexity. https://en.wikipedia.org/wiki/Hash_table
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