Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log(n) vs. constant time

HashSet class has a constant time performance for the basic operations (add, remove, contains and size).

TreeSet has log(n) time cost for the basic operations (add, remove and contains methods).

Because HashSet is constant, will it always be faster than log(n) ?

like image 714
user3430459 Avatar asked Mar 21 '26 17:03

user3430459


1 Answers

No, that's not how big-Oh works. Actual performance may differ.

Bubble sort is notoriously slow, but for a small data set it might actually perform well compared to other "better" algorithms. The big-Oh describes asymptotic behavior, not specific individual scenarios.

like image 74
duffymo Avatar answered Mar 24 '26 10:03

duffymo



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!