![]() |
VOOZH | about |
The std::set::count() is a built-in function in C++ STL which is used to count the number of times an element occurs in the set container. std::set container stores unique elements, so it can only return 1 or 0. Therefore, it is only used for checking if the element exists in the set or not.
Example
1 0
s.count(val);
where, s is the name of std::set container.
The std::set container is generally implemented by a self-balancing binary search tree. The set::count() function searches for the given value in the set. So, search operation in self-balancing BST,
Time Complexity: O(log n), where n is the number of elements in the set.
Auxiliary Space: O(1)
The following examples illustrates the use of set::count() function:
Not exists
Set count of 2: 1 Multiset count of 2: 2