Why is the worst case complexity of std::unordered_multiset insert is linear? I understand why is that the case for std::unordered_set (you have to check that inserted value is not in the set) but for multiset I don't get it. Am I missing something obvious?
Complexity of std::unordered_multiset insert
1.8k Views Asked by JamesJohnson At
1
There are 1 best solutions below
Related Questions in C++
- C++ using std::vector across boundaries
- Linked list without struct
- Connecting Signal QML to C++ (Qt5)
- how to get the reference of struct soap inherited in C++ Proxy/Service class
- Why we can't assign value to pointer
- Conversion of objects in c++
- shared_ptr: "is not a type" error
- C++ template using pointer and non pointer arguments in a QVector
- C++ SFML 2.2 vectors
- Lifetime of temporary objects
- I want to be able to use 4 different variables in a select statement in c ++
- segmentation fault: 11, extracting data in vector
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- How can I print all the values in this linked list inside a hash table?
- Configured TTL for A record(s) backing CNAME records
Related Questions in C++11
- C++ using std::vector across boundaries
- Using QPointer and QObject::connect with C++11
- Using std::vector<> and std::shared_ptr<> should cause error
- invoking function for each variadic template arguments and passing the result as constructor arguments
- Different behavior of async with Visual Studio 2013(Windows8.1) and GCC 4.9(Ubuntu14.10)
- Whether to use T const& or T&&
- C++ IRC Bot Buffer Error
- Downcast from a container of Base* to Derived* without explicit conversion
- Assigning values in a vector in non-sequential order
- Can I use C++11 list-initializer syntax for vectors with variables?
- is it fine to use auto keyword in function parameter?
- Variadic template method and std::function - compilation error
- Clustering on Graph (using Boost Graph Library)
- libc++ difference between vector::insert overloads
- Cannot convert argument1 to const char
Related Questions in STL
- C++ using std::vector across boundaries
- Downcast from a container of Base* to Derived* without explicit conversion
- C++ Custom std::map<> key class causing memory violation
- How to get rid of the ".\r\n" characters appended to the error message from FormatMessageA?
- What is the equivalent of boost::system::error_code with GetLastError in C++ Standard Library?
- How to insert data into map where one parameter is an object?
- C++11 template instance wrapping vector makes error
- No viable conversion std::weak_ptr to std::shared_ptr for method call
- syntax: doing binary_search (STL) for sorted vector of pointers to struct
- Linker error using VS 2015 RC, can't find symbol related to std::codecvt
- Pass vector of char vectors to char**
- Android NDK / Exceptions?
- How to insert data into nested map in c++?
- Which STL container(s)/algorithm(s) could I use to solve this?
- Is there a way to iterate over at most N elements using range-based for loop?
Related Questions in TIME-COMPLEXITY
- Time complexity of the algorithm?
- Shell Vs. Hibbard time complexity comparison
- Time complexity of swapping elements in a python list
- constant time complexity: O(x^c)
- Java TreeMap time complexity - lowerKey
- Complexity of LSD string sort (cfr. Algorithms by Sedgewick & Wayne)
- How to search a unknown composite key for dictionary in O(1) in c#
- Confusion about why NP is contained in PSPACE, EXPTIME etc
- Depth first search or backtrack recursion for finding all possible combination of letters in a crossword puzzle/boggle board?
- Time complexity of nested for loops
- TIme complexity of various nested for loops
- Best case performance of quicksort (tilde notation)
- Ranking a given list of integers in less than O(n^2)
- Bellman-Ford algorithm proof of correctness
- Division of very large numbers
Related Questions in UNORDERED-MULTISET
- Iterator invalidation with unordered_set/unordered_multiset
- std::unordered_multiset exception iterating bucket
- Generating Subsets of a Multiset in Ascending Order of the Sums of the Elements of the Subset
- Why does the == operator of std::unordered_multiset<T> returns wrong result when T is a pointer type?
- How to reduce the memory consumption of unordered_multiset?
- What are some uses of local iterator for STL unordered containers?
- Use of multisets in C++
- Remove only one item from unordered_multiset
- Why multiset keeps separate instances of repeated elements instead of their count?
- Number of distinct elements of std::unordered_multiset
- how to end a loop at a particular time in unordered_multiset
- what is wrong with this code ? it's not showing any output after executing
- Python inventory of objects
- Usecases for std::unordered_multiset
- std::distance goes wrong for unordered map
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
The worst case complexity for
std::unordered_multiset::insert()is linear because:For example, consider the case where
5,13, and13are inserted into anunordered_multisetthat has4buckets, andunordered_multiset::key_eq(5, 13)returnsfalse. In this case,unordered_multiset::hash_function(5)returns different hash codes for both5and13. Despite having different hash codes, these elements may still be inserted into the same bucket. If the hash function for an integer returns the integer itself, and the bucket index is the result of the hash code modulus the number of buckets, then:5is hashed to5, and with4buckets, it is placed in bucket1.13is hashed to13, and with4buckets, it is placed into bucket1as well.While
unordered_set::insert()checks to prevent duplicates during insertion,unordered_multiset::insert()identifies where to insert the element for equivalent-key grouping. In the worst case, the bucket contains[5, 13]when inserting the final13, and upon iterating over all elements, the bucket contains[5, 13, 13]. As iteration over all elements occurs, the complexity is linear insize().It is worth noting that a rehash may occur during
unordered_multiset::insert(), andunordered_multiset::rehash()is specified as having a complexity with an average case linear insize()and the worst case is quadratic. During a rehash, all elements in the original hash table are iterated over and inserted into a new hash table. As iteration has a complexity linear insize(), and as identified above, each insertion has a worse case linear insize(), the resulting worst case isO(size()*size()).