Skip to main content

Priority Queue

A priority queue is like a heap. By default, it’s a max-heap (the largest element is always at the top).

Min-Heap

To make it a min-heap:

Deque (Double-Ended Queue)

A deque allows insertion and deletion from both ends in O(1)O(1).

Lower Bound and Upper Bound

Very useful for binary search on sorted containers.
  • lower_bound: Returns an iterator to the first element \ge value.
  • upper_bound: Returns an iterator to the first element >> value.

Custom Sorting with STL

You can use std::sort with custom comparators or use std::greater<T>().

Practice

Sheet 6: STLs 2

Practice problems for this tutorial.