Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How do you put them into the set in O(n), exactly?



Set insertion is O(n) in this case. An O(1) set insertion refers to constant time regardless of the size of the inserted element, but if you add one element to a set, then add a billion elements to the set, the latter will take about a billion times longer.


Right, inserting N items takes O(N), which is what I said.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: