+ 1
Time complexity of deque
What's time complexity of erase and find for deque ? Any issue to use these two on deque? Not getting proper source to go through these concepts
1 Odpowiedź
0
The time complexity of the erase operation in a deque typically has a linear relationship with the number of elements in it, which means it is O(n), where n represents the number of elements in the deque. On the other hand, the find operation in a deque involves a linear search through the elements, resulting in a time complexity of O(n) in the worst case scenario. Using these operations on a deque may not be as efficient as on other data structures like a set or map because of the linear time complexity involved. If you frequently need to perform these operations on a large number of elements, you might want to consider using a different data structure that provides faster lookups and deletions, such as set or map which have logarithmic time complexities for these operations.
My suggestion is, when in doubt about data structure usage or complexity analysis, it's always helpful to refer to academic textbooks on data structures and algorithms.