Your concept feed

21 ideas

A few small steps. No rush.

Follow the connections in this topic

Let’s picture it

Only the smallest waiting item matters next.

5
1
4

Tasks cost 5,1,4. We need the cheapest task now, then the next cheapest after adding new tasks.

Swipe when you’re ready
One little change

A heap orders one frontier, not everything.

minimum root
partly ordered below

The root is smallest. Removing it repairs only the tree paths needed to expose the next minimum.

Same idea. One more small step.
Now it has a name

Push and pop logarithmically.

push
peek minimum
pop

Use a heap when priorities change incrementally and repeatedly sorting the entire collection would waste work.

Want to try a tiny question?
No pressure. Just try it.

Does iterating the internal heap array return sorted order?

You can also keep scrolling
1 / 4
Heaps & priority

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

Two trees can make different promises.

8
3
10

In a search tree, smaller keys go left and larger keys go right. We’ll use distinct keys here.

1 / 3
Let’s picture it

Count before ranking.

a:3
b:2
c:1

In [a,a,a,b,b,c], frequencies are a:3, b:2, c:1. The raw input order is not the priority.

Swipe when you’re ready
One little change

Keep only k winners.

winner a
winner b
root = weaker

For k=2, a min-heap of size two remembers the weakest current winner at its root.

Same idea. One more small step.
Now it has a name

Discard what cannot enter.

candidate
smallest winner
replace?

Each new frequency competes with the root. The heap never needs to hold more than k distinct values.

Want to try a tiny question?
No pressure. Just try it.

Which heap root is useful when keeping the k largest frequencies?

You can also keep scrolling
1 / 4
Heaps & priority

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

Only the smallest waiting item matters next.

5
1
4

Tasks cost 5,1,4. We need the cheapest task now, then the next cheapest after adding new tasks.

1 / 3
Let’s picture it

Several lists offer one front each.

1
2
0

Lists [1,4], [2,3], and [0,7] each expose their smallest remaining value.

Swipe when you’re ready
One little change

The global next value is among those fronts.

pop 0
push 7

A min-heap chooses 0. After using it, only its list contributes a new front: 7.

Same idea. One more small step.
Now it has a name

The frontier stays small.

k front nodes
one output chain

At most one node from each list waits in the heap, even when the total output is large.

Want to try a tiny question?
No pressure. Just try it.

After popping one node, which list can offer a newly eligible node?

You can also keep scrolling
1 / 4
Heaps & priority

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

Only two front nodes can be next.

1→4
2→3

For 1→4 and 2→3, every later node is at least its list’s front. Compare 1 and 2.

1 / 3
Let’s picture it

One middle changes as values arrive.

2
2,8
2,5,8

After 2, median is 2. After 2,8 it is 5. After 2,5,8 it is 5.

Swipe when you’re ready
One little change

Split values into two halves.

lower max
|
upper min

A max-heap holds the lower half; a min-heap holds the upper half. Their roots touch at the middle.

Same idea. One more small step.
Now it has a name

Balance sizes after each insertion.

size L = size R
or L = R+1

Keep lower equal in size to upper or one larger. Then one or two roots give the median.

Want to try a tiny question?
No pressure. Just try it.

What invariant relates every lower-half value to every upper-half value?

You can also keep scrolling
1 / 4
Heaps & priority

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

Only the smallest waiting item matters next.

5
1
4

Tasks cost 5,1,4. We need the cheapest task now, then the next cheapest after adding new tasks.

1 / 3
You've reached the end of these ideas.Try them without the labels