Suppose I have a vector of N items and I want to remove k random elements from it. The complexity of vector erase is linear in the number of items after the erased item. So for k random elements it would be O(Nk). My question is the following: Would it be more efficient to convert a vector to a list in O(N) time and perform erase in the list format in constant time?
I know it depends on N and k, and benchmarking would reveal the best for a specific case. But, I wonder if it is a common thing that people usually do?
Aucun commentaire:
Enregistrer un commentaire