Unordered sets have to pay for their O(1) average access time in a few ways: For instance, hash tables are βO(n)β at worst case. O(1) is the average case. Trees are βO(log n)β at worst. People tend to overlook the fact that hashtables have O(1) average-case access time, meaning they can occasionally have big delays.
red-black trees, an advanced self balancing tree.
unordered_set, We need single element access i.e. no traversal.
- set uses less memory than unordered_set to store the same number of elements.
- unordered used the linkedlist
- For a small number of elements, lookups in a set might be faster than lookups in an unordered_set.
- Even though many operations are faster in the average case for unordered_set, they are often guaranteed to have better worst case complexities for set (for example insert).
- That set sorts the elements is useful if you want to access them in order.
- You can lexicographically compare different sets with <, <=, > and >=. unordered_sets are not required to support these operations.
[[β.β,β.β,β#β,β.β,β.β,β.β,β.β,β#β], [β.β,βBβ,β.β,β.β,β.β,β.β,β.β,β#β], [β.β,β.β,βSβ,β.β,β.β,β.β,β.β,β.β], [β.β,β#β,β.β,β.β,β.β,β.β,β.β,β.β], [β.β,β.β,β.β,β.β,β.β,β.β,β.β,β.β], [β.β,β.β,β.β,βTβ,β.β,β.β,β.β,β.β], [β.β,β.β,β.β,β.β,β.β,β.β,β.β,β#β], [β.β,β#β,β.β,β.β,β.β,β.β,β.β,β.β]]