Skip to main content

What is the STL?

The Standard Template Library is a collection of ready-to-use data structures and algorithms in C++. Mastering the STL is essential for competitive programming — it saves you from writing boilerplate code.

Vector

A dynamic array that can grow and shrink.

Iterating

Set

A collection of unique elements, automatically sorted. Operations are O(log n).

Multiset

Like set, but allows duplicates:
In multiset, erase(value) removes all occurrences. To remove just one, use erase(find(value)).

Map

A collection of key-value pairs, sorted by key. Operations are O(log n).

Frequency counting with map

Stack

LIFO (Last In, First Out):

Queue

FIFO (First In, First Out):

Summary table

Practice

Sheet 5: STLs 1

Practice problems for this tutorial.