The STL Cheat Sheet - Set, Map is a quick reference guide or document that provides information and examples for using the Set and Map containers in the Standard Template Library (STL) in C++. These containers are used for storing and manipulating collections of unique elements (Set) and key-value pairs (Map) in a sorted manner.
Q: What is an STL?
A: STL stands for Standard Template Library.
Q: What is a set in STL?
A: A set is an STL container that stores unique elements in a sorted manner.
Q: What is a map in STL?
A: A map is an STL container that stores key-value pairs in a sorted manner based on the keys.
Q: How do you insert elements into a set in STL?
A: You can insert elements into a set using the insert() function.
Q: How do you insert key-value pairs into a map in STL?
A: You can insert key-value pairs into a map using the insert() function or the subscript operator[].
Q: How do you iterate over elements in a set in STL?
A: You can use iterators to iterate over elements in a set.
Q: How do you iterate over key-value pairs in a map in STL?
A: You can use iterators to iterate over key-value pairs in a map.
Q: Can a set contain duplicate elements?
A: No, a set can only contain unique elements.
Q: Can a map have multiple entries with the same key?
A: No, a map can only have one entry for each unique key.
Q: What is the time complexity of searching for an element in a set?
A: The time complexity is O(log(n)) where n is the number of elements.
Q: What is the time complexity of searching for a key in a map?
A: The time complexity is O(log(n)) where n is the number of key-value pairs.
Q: Can elements in a set be modified?
A: No, elements in a set are immutable.
Q: Can values in a map be modified?
A: Yes, values in a map can be modified using iterators or the subscript operator[] based on the key.