Introduction to Sets:
Sets are associative containers that each element has to be unique. You can not modify an element in a set but you can remove it, modify it, and then inserted it.
Some basic functions associated with Sets:
- name.begin() → Returns an iterator to the first element in the set
- name.end() → Returns an iterator to the next element of the last in the set
- name.size() → Returns the number of elements in the set
- name.max_size() → Returns the number of elements that a set can hold
- name.empty() → Returns whether the set is empty
You can see more functions in the implementation.
Implementation: https://github.com/Aris12345678/Algorithms/blob/main/set.cpp
Introduction to Maps:
Maps are associative containers that store elements in the following way. Each element has a key and a value. Two values can’t have the same key.
Some basic functions associated with Maps:
- name.begin() → Returns an iterator to the first element in the map
- name.end() → Returns an iterator to the next element of the last in the map
- name.size() → Returns the number of elements in the map
- name.max_size() → Returns the number of elements that a map can hold
- name.empty() → Returns whether the map is empty
- name.insert({key, value}) → Inserts a new element in the map
- name.erase(iterator position) → Removes the element at the position pointed by the iterator
- name.erase(g) → Removes the element with key equal to g
- name.clear() → Removes every element in the array
Implementation: https://github.com/Aris12345678/Algorithms/blob/main/map.cpp
Problems:
- https://cses.fi/problemset/task/1621 (simple)
- https://judge.yosupo.jp/problem/associative_array (simple)
- https://cses.fi/problemset/task/1640 (Easy)
- http://www.usaco.org/index.php?page=viewproblem2&cpid=667 (Medium)
Reference: