Is it safe to ignore set? | Sololearn: Learn to code for FREE!

+4

Is it safe to ignore set?

Hi Below is my understanding ( Correct me if it is wrong ): - SET is implemented using RED BLACK tree.... Hence element in it will be sorted as per tree form not in ascending or descending order (so no specific requirement of sorting can be fulfilled). - UNORDERED SET is implemented using HASHING and hence your element is not sorted. - UNORDERED SET takes O(long n) time for insertion , deletion or search. - SET takes O(1) time for insertion , deletion or search. Having said above all, can we go with UNORDERED SET each time instead of choosing between SET and UNORDERED SET? Is this safe to assume or am I missing something?

7/7/2020 5:18:47 AM

Ketan Lalcheta

3 Answers

New Answer

+5

Can include this.. The Unordered_set allows only unique keys, for duplicate keys unordered_multiset should be used. Rest all are perfect :)

+4

Multisets are kind of associative containers same to set, which has exception that multiple elements can have same values. But I also do l much about it's specification over unordered one :(

+3

Aditya , yeah it's true... Definitely, we need multi version of set and map both for normal and unordered scenario. But I could not find specific use case where one should chose set over unordered_set