4 ms·
How do you put them into the set in O(n), exactly?
by brians 6y ago
How do you put them into the set in O(n), exactly?
- raldi 6y agoSet insertion is O(1): https://stackoverflow.com/a/44080017 https://stackoverflow.com/a/44080017
- margalabargala 6y agoSet 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.
- deleted 6y ago[deleted]
- raldi 6y agoRight, inserting N items takes O(N), which is what I said.