STL (Standard Template
Library)
What is STL?
The Standard Template Library (STL) is a set of C++
template classes to provide common programming
data structures and functions such as lists, stacks,
arrays, etc.
Question
Find the frequency of all the numbers??
Eg. 1 1 2 2 1 1 3 5 5
1 - 4
2 -2
3 - 1
5 - 2
Solutions
1. Brute Force
2. Hashing
Problems with this solution
1. Too much memory waste
2. Not able to solve for big numbers
MAP to the rescue
● #include <map>
● Key Value store
● Traversing through iterators
● Search in log(n)
● size(), find(),clear
Map properties
● Stores in sorted order
● Searching in logn
● Erase in logn
Set
● When to use?
● Syntax
● Traversing
● Find function
● Complexities
Vector
● Similar to array
● Push_back
● Size
Other STL functions
● sort
● next_permutation
● Reverse
● Memset
● __gcd
Questions
● https://www.hackerrank.com/challenges/cpp-maps/problem
● https://www.hackerrank.com/challenges/cpp-sets/problem
● https://www.hackerearth.com/problem/algorithm/shikhar-stl/
● https://www.codechef.com/problems/KJCP02
● https://www.codechef.com/problems/CSS2
● https://www.codechef.com/LRNDSA02/problems/NOTALLFL
● https://www.codechef.com/JUNE20B/problems/CHFICRM
● https://www.codechef.com/DEC14/problems/CAPPLE/

STL - Map, Set, Vector