time complexity of this given data structure

user1335175

I am just starting to learn about the time complexities and I just want to make sure I am getting this right.

if we have a unordered_map<string, set<int>>

note that organized as hash tables that never allow the load factor to exceed some constant.

Lets say string are business names and in set<int> we have employee ID's, if we want to print all employee id's in some given business, what will be the time complexity. And here is my logic, please let me know if I am heading in right direction.

My logic is this, since hash table load constant will not exceed some constant, finding a particular business will be constant time operation so O(1). Printing all names in a list is basically BST in order traversal so it will be O(N) on average. hence overall it will be O(1)+O(N) which is basically O(N). is this correct?

meneldal

Well the important thing to understand is how you're counting the complexity.

Let's say you have N entries in the first container and the std::set<int> contains M elements. With a container that allows fast search, the first part is O(1) then printing is O(M).

However, if you were using something like a std::vector the complexity would be O(N)+O(M) (because the search is slow). For a regular map, it would be O(logN)+O(M).

Since N and M are (without more data) uncorrelated, you can't put them together in the O expressions.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

time complexity of this given data structure

From Dev

Efficient (time and space complexity) data structure for dense and sparse matrix

From Dev

What is the time complexity of the given algorthm?

From Dev

Time Complexity of the given nested loops

From Dev

What is the time complexity of the given code?

From Dev

Find the time complexity of a given function

From Dev

Time Complexity of the given nested loops

From Dev

Create algorithm with given time complexity

From Dev

What is the time complexity of given code?

From Dev

Time complexity of Data Structures

From Dev

Time complexity of Data Structures

From Java

Time complexity of the given function with constant loop and recursion

From Dev

Improving the time complexity of all permutations of a given string

From Dev

how to calculate time complexity for the given code?

From Dev

Determining the Time and Space complexity of a given code

From Dev

Confusion with time complexity in "Find a pair with the given difference"

From Dev

Design a data structure with insertion, deletion, get random in O(1) time complexity,

From Dev

Space Complexity of an initialised pointer data structure

From Dev

Scala data structure and complexity O(1)

From Dev

Set combination data structure (And storage complexity)

From Dev

Space Complexity of an initialised pointer data structure

From Dev

Dictionary data structure + fast complexity methods

From Dev

What data structure to find number of elements in a given range in O(log n) time?

From Dev

Time complexity of my algorithm for creating a target array in the given order

From Dev

Time complexity of my algorithm for creating a target array in the given order

From Dev

What is the time complexity for finding the maximum value less than a given value?

From Dev

C++ : suitable Data Structure for this given scenario

From Dev

Reading from a binary file with a given data structure

From Dev

Appropriate data structure for time series

Related Related

  1. 1

    time complexity of this given data structure

  2. 2

    Efficient (time and space complexity) data structure for dense and sparse matrix

  3. 3

    What is the time complexity of the given algorthm?

  4. 4

    Time Complexity of the given nested loops

  5. 5

    What is the time complexity of the given code?

  6. 6

    Find the time complexity of a given function

  7. 7

    Time Complexity of the given nested loops

  8. 8

    Create algorithm with given time complexity

  9. 9

    What is the time complexity of given code?

  10. 10

    Time complexity of Data Structures

  11. 11

    Time complexity of Data Structures

  12. 12

    Time complexity of the given function with constant loop and recursion

  13. 13

    Improving the time complexity of all permutations of a given string

  14. 14

    how to calculate time complexity for the given code?

  15. 15

    Determining the Time and Space complexity of a given code

  16. 16

    Confusion with time complexity in "Find a pair with the given difference"

  17. 17

    Design a data structure with insertion, deletion, get random in O(1) time complexity,

  18. 18

    Space Complexity of an initialised pointer data structure

  19. 19

    Scala data structure and complexity O(1)

  20. 20

    Set combination data structure (And storage complexity)

  21. 21

    Space Complexity of an initialised pointer data structure

  22. 22

    Dictionary data structure + fast complexity methods

  23. 23

    What data structure to find number of elements in a given range in O(log n) time?

  24. 24

    Time complexity of my algorithm for creating a target array in the given order

  25. 25

    Time complexity of my algorithm for creating a target array in the given order

  26. 26

    What is the time complexity for finding the maximum value less than a given value?

  27. 27

    C++ : suitable Data Structure for this given scenario

  28. 28

    Reading from a binary file with a given data structure

  29. 29

    Appropriate data structure for time series

HotTag

Archive