What is the worst case scenario for an unordered_map?

Tahlil

I have found many posts about the complexity of map and unordered_map. It is said that unordered_map has worst case complexity of O(N). For my purpose I will have input as sorted values like 1 2 5 6 9 11 12... I need to insert or find and delete a value. I will have to do insert/delete quite frequently. I thought of using set which has log(n) complexity in all cases. And then I stumbled upon unordered_map which has best O(1) complexity. But I need to understand in my scenario will I face the worst case scenario of unordered_map? And what will be the scenario?

EDIT: In my case all the values will be unique.

quantdev

unordered_map worst case usually happens when the hash function is producing collisions for every insertion in the map.

I said "usually" because the standard only specifies the worst case complexity, not when or how it will happen, so theoretically the answer to your question is that it is implementation defined.

Since all your values are unique, and apparently integers (which present very good hashing, possibly optimal _ this is again implementation dependent), you will not run into this worst case scenario. insert/find/delete will be O(1), so it looks like a reasonable choice.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Worst case scenario Quicksort binary tree

From Dev

What is the worst-case running time for this algorithm?

From Dev

What is worst case running time for the given algorithm

From Dev

what is the best and worst case analysis of these algorithms?

From Dev

How do advanced computer users plan for the worst case scenario with their password managers?

From Dev

unordered_map: what to return if key is not in map?

From Dev

What is the (worst-case) time analysis for the following loop?

From Dev

What are the worst-case time bounds for each operation on a Fibonacci heap?

From Dev

Quicksort - Worst case condition

From Dev

worst case for this code?

From Dev

Worst test case for SPFA

From Dev

Worst Case Running time

From Dev

No of steps taken in worst case

From Dev

Insertion sort worst case

From Dev

What is the difference between unordered_map::emplace and unordered_map::insert in C++?

From Dev

What distinguishes a user story/feature from a use case/scenario?

From Dev

What would be a good use-case scenario for the Spliterator in Java 8?

From Dev

What is the order of growth of the worst case running time of the following code fragment as a function of N?

From Dev

What's the worst-case space complexity for the All Paths Sum problem for an unbalanced tree?

From Dev

What is the Best/Worst/Average Case Big-O Runtime of a Trie Data Structure?

From Dev

What is Big-O runtime of the standard random number generator in python? (Worst-case)

From Dev

Binary search - worst/avg case

From Dev

TSP: Worst case ratio grows

From Dev

Worst case time complexity for the code

From Dev

Amortized cost vs worst case

From Dev

Worst case time complexity for the code

From Dev

KMP algorithm worst case analysis

From Dev

How to calc worst case complixity?

From Dev

What could cause clang to not find the unordered_map header?

Related Related

  1. 1

    Worst case scenario Quicksort binary tree

  2. 2

    What is the worst-case running time for this algorithm?

  3. 3

    What is worst case running time for the given algorithm

  4. 4

    what is the best and worst case analysis of these algorithms?

  5. 5

    How do advanced computer users plan for the worst case scenario with their password managers?

  6. 6

    unordered_map: what to return if key is not in map?

  7. 7

    What is the (worst-case) time analysis for the following loop?

  8. 8

    What are the worst-case time bounds for each operation on a Fibonacci heap?

  9. 9

    Quicksort - Worst case condition

  10. 10

    worst case for this code?

  11. 11

    Worst test case for SPFA

  12. 12

    Worst Case Running time

  13. 13

    No of steps taken in worst case

  14. 14

    Insertion sort worst case

  15. 15

    What is the difference between unordered_map::emplace and unordered_map::insert in C++?

  16. 16

    What distinguishes a user story/feature from a use case/scenario?

  17. 17

    What would be a good use-case scenario for the Spliterator in Java 8?

  18. 18

    What is the order of growth of the worst case running time of the following code fragment as a function of N?

  19. 19

    What's the worst-case space complexity for the All Paths Sum problem for an unbalanced tree?

  20. 20

    What is the Best/Worst/Average Case Big-O Runtime of a Trie Data Structure?

  21. 21

    What is Big-O runtime of the standard random number generator in python? (Worst-case)

  22. 22

    Binary search - worst/avg case

  23. 23

    TSP: Worst case ratio grows

  24. 24

    Worst case time complexity for the code

  25. 25

    Amortized cost vs worst case

  26. 26

    Worst case time complexity for the code

  27. 27

    KMP algorithm worst case analysis

  28. 28

    How to calc worst case complixity?

  29. 29

    What could cause clang to not find the unordered_map header?

HotTag

Archive