Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift set contains complexity

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

like image 948
Haris Avatar asked Jun 27 '26 19:06

Haris


1 Answers

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

like image 75
RaviYadav Avatar answered Jun 30 '26 07:06

RaviYadav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!