C++ Heaps Pairs Sorting

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/23

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:17 AM on 5/30/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

24 Terms

1
New cards

default priority queue

max heap

2
New cards

declare max heap

priority_queue<int> pq;

3
New cards

declare min heap

priority_queue<int, vector<int>, greater<int>> pq;

4
New cards

push heap

pq.push(x);

5
New cards

top heap

pq.top();

6
New cards

pop heap

pq.pop();

7
New cards

heap push time

O(log n)

8
New cards

heap pop time

O(log n)

9
New cards

declare pair

pair<int, int> p;

10
New cards

create pair

{a, b} or make_pair(a, b)

11
New cards

access pair first

p.first

12
New cards

access pair second

p.second

13
New cards

declare vector of pairs

vector<pair<int, int>> v;

14
New cards

sort pairs default

sort(v.begin(), v.end());

15
New cards

sort by second value

sort(v.begin(), v.end(), [](auto& a, auto& b){ return a.second < b.second; });

16
New cards

sort descending custom

sort(v.begin(), v.end(), [](auto& a, auto& b){ return a > b; });

17
New cards

binary search function

binary_search(v.begin(), v.end(), x)

18
New cards

lower bound meaning

first element not less than x

19
New cards

upper bound meaning

first element greater than x

20
New cards

lower bound code

lower_bound(v.begin(), v.end(), x)

21
New cards

upper bound code

upper_bound(v.begin(), v.end(), x)

22
New cards

get index from iterator

it - v.begin()

23
New cards

include everything

#include <bits/stdc++.h>

24
New cards

standard namespace

using namespace std;