m***t 发帖数: 254 | 1 say if i want to add an element to a set, and if there is duplicate, i will
only want keep one copy, what is
the complexity for each insertion? log(n)? so if n elements insertion, nlogn
? | l***t 发帖数: 81 | 2 yes.
will
nlogn
【在 m***t 的大作中提到】 : say if i want to add an element to a set, and if there is duplicate, i will : only want keep one copy, what is : the complexity for each insertion? log(n)? so if n elements insertion, nlogn : ?
| m***t 发帖数: 254 | 3 what if i use hash?
【在 l***t 的大作中提到】 : yes. : : will : nlogn
| S*****n 发帖数: 227 | 4 then O(1) and O(n)
【在 m***t 的大作中提到】 : what if i use hash?
| N********n 发帖数: 8363 | 5 Usually a set is implemented as a balanced tree. If you do frequent
set intersection and unioning then you may go with bit-vector.
will
【在 m***t 的大作中提到】 : say if i want to add an element to a set, and if there is duplicate, i will : only want keep one copy, what is : the complexity for each insertion? log(n)? so if n elements insertion, nlogn : ?
| l***t 发帖数: 81 | 6 In STL set is implemented by balanced binary tree.
If you use hash, then O(1).
【在 m***t 的大作中提到】 : what if i use hash?
|
|