All lessons

4. Stacks & Queues

Priority queues and heaps intro

0 of 5 activities0%

Reading 1

Best-first retrieval

Open

A priority queue serves the minimum or maximum key next, not insertion order.

Usually implemented as a binary heap: O(log n) push/pop, O(1) peek.

C++: priority_queue (max-heap by default).

priority_queue<int> pq;
pq.push(3); pq.push(10); pq.push(1);
cout << pq.top(); // 10

Check 2

Default C++ PQ

Open

std::priority_queue is by default a

Fill in 3

Tree shape

Open

Priority queues are commonly implemented with a binary

Try it 4

Max heap top

Open

Push and print top.

main.cpp
Loading editor…
Output will appear here.

Assignment 5

Maximum of list

Open

Read n and n ints. Print the maximum (priority-queue idea).

main.cpp
Loading editor…