Your concept feed
21 ideas
Follow the connections in this topic
A small step before this topic
Let’s picture it Let’s start with three stops.
Home. Then the park. Then the café. Just a few things in a row.
One little change Point to the middle one.
The park is second. In Python, its position is 1, because counting starts at 0.
Now it has a name That’s a list.
A list keeps things in order. An index is just a position in that list.
No pressure. Just try it.Which place is at position 0?
1 / 4 A small step before this topic
Let’s picture it Now visit each stop.
You don’t need three different instructions. “Visit the next place” works each time.
One little change One, then the next.
Finish home. Move to the park. Then do the same at the café.
Now it has a name That repeat is a loop.
One small action, repeated for each item. Three stops mean three visits.
No pressure. Just try it.Add one more stop. How many visits now?
1 / 4 A small step before this topic
Let’s picture it What if it rains?
Let’s choose the café on rainy days, and the park on sunny days.
One little change Today is sunny.
The rule stays the same. The weather changed, so we choose the other place.
Now it has a name That’s an if / else.
Raining?
Yes: café
No: park
A condition is a yes-or-no question. Its answer chooses which step happens next.
No pressure. Just try it.It’s raining. Where does our rule send us?
1 / 4 A small step before this topic
Let’s picture it Name a tiny job.
Our job is “add one.” Give it 3, and it gives back 4.
One little change Try a new input.
Give the same job 8. It gives back 9. We can reuse the instructions.
Now it has a name That job is a function.
Input goes in. An answer comes back. In Python, return sends the answer back.
No pressure. Just try it.What does add-one return for 5?
1 / 4 A small step before this topic
Let’s picture it Picture a pile of plates.
Blue goes down first. Pink goes on top.
One little change Take the top one.
Pink comes off first, even though blue arrived first.
Now it has a name That’s a stack.
Last in, first out. Paused function calls work this way too: finish the newest call, then return.
No pressure. Just try it.Add green on top. Which plate comes off next?
1 / 4 A small step before this topic
Let’s picture it Have we visited the park?
Keep a little checklist of places we’ve seen.
One little change Write park again.
We still only need one check beside park. We’re remembering whether, not how many times.
Now it has a name That’s a set.
A set keeps distinct items. “Is park in here?” becomes a quick membership check.
No pressure. Just try it.Add park twice. How many copies in a set?
1 / 4 A small step before this topic
Let’s picture it Let’s remember a little more.
The park is five minutes away. Write that beside its name.
One little change Look it up later.
Ask for “park.” The notebook gives you 5. No need to measure the walk again.
Now it has a name That’s a dictionary.
A key finds a value. Here, the place name is the key and the time is the value.
No pressure. Just try it.We now write park: 6. What does park return?
1 / 4 A small step before this topic
Let’s picture it Draw our little walk.
A dot for each place. A line where we can walk directly.
One little change Two short walks can join.
Home to park, then park to café. We can reach the café without a direct road.
Now it has a name Dots and links have names.
A dot is a node. A link is an edge. Together, they make a graph.
No pressure. Just try it.Must two places share a direct road to be reachable?
1 / 4 A small step before this topic
Let’s picture it Same door. One small difference.
You have a key. Your friend doesn’t. The door is the same, but your next move isn’t.
One little change Remember the key.
If we only write down “at the door,” we lose something important.
Now it has a name That little note is a state.
A state remembers what we need to continue. Here: where we are, and whether we have the key.
No pressure. Just try it.Is “at the door” enough to decide if we can enter?
1 / 4 A small step before this topic
Let’s picture it How many little jobs?
Visit three places. Say hello once at each. That’s three hellos.
One little change Now try every pair.
Three people each greet all three people, including themselves for this toy count. That’s nine greetings.
Now it has a name Count how the work grows.
One pass grows with n. Trying every pair grows with n × n. Code length doesn’t tell us that.
No pressure. Just try it.With 4 items, how many ordered pairs, including self-pairs?
1 / 4 A small step before this topic
Let’s picture it Find 8 in a sorted row.
Start with 2, 4, 6, 8, 10. Look at the middle: 6.
One little change Keep the side that can work.
8 is bigger than 6. Everything on the left is too small, so we can leave it behind.
Now it has a name Keep one promise.
If 8 is present, it stays in the part we keep. That repeating promise is called an invariant.
No pressure. Just try it.Would this left-or-right shortcut work on an unsorted row?
1 / 4 A small step before this topic
Let’s picture it Open a box.
There’s a smaller box inside. We already know how to open a box.
One little change Do the same small job again.
Open the smaller box. Keep going until there isn’t another box inside.
Now it has a name That’s the idea of recursion.
A function asks itself to handle a smaller case. The empty box is our stopping point: the base case.
No pressure. Just try it.What if every box contains another box forever?
1 / 4 A small step before this topic
Let’s picture it Try every pair first.
In a sorted row [1,2,4,7], seek a pair totaling 9. Checking every pair repeats work.
One little change Look at both ends.
1 + 7 is too small. Moving the right pointer left only makes the sum smaller, so move the left pointer right.
Now it has a name Discard with a reason.
too small → left
too large → right
equal ✓
Now 2 + 7 = 9. Each move removes an entire family of impossible pairs, so both pointers move only forward overall.
No pressure. Just try it.When the sum is too small, which pointer can safely move?
1 / 4 A small step before this topic
Let’s picture it Each node knows only the next node.
A holds 3 and points to B. B holds 5 and points to C. There is no index jump to C.
One little change Keep the entrance.
The head reference is how we reach the chain. Losing it can make the remaining nodes unreachable.
Now it has a name Pointer updates change topology.
Changing one next reference can detach, join, or cycle a chain. Save any reference needed after the change.
No pressure. Just try it.Can a singly linked list read its kth item in O(1)?
1 / 4 A small step before this topic
Let’s picture it Only two front nodes can be next.
For 1→4 and 2→3, every later node is at least its list’s front. Compare 1 and 2.
One little change Attach the smaller front.
Append 1 and advance only that list. The same promise remains for 4 and 2.
Now it has a name A dummy head removes a special case.
Build after a sentinel, then return sentinel.next. When one list ends, attach the other suffix.
No pressure. Just try it.Must we allocate new nodes to merge?
1 / 4 A small step before this topic
Let’s picture it Count a tiny family of dots.
One parent has two children. Each child says, “There’s one of me.”
One little change Let the answers travel up.
The parent adds the two answers, then counts itself: 1 + 1 + 1.
Now it has a name That works for bigger trees too.
my answer
left answer
right answer
Ask each child about its little tree. Combine the answers. You don’t need to hold the whole tree in your head.
No pressure. Just try it.Do we also count the parent itself?
1 / 4 A small step before this topic
Let’s picture it Two trees can make different promises.
In a search tree, smaller keys go left and larger keys go right. We’ll use distinct keys here.
One little change A heap promises something else.
A min-heap keeps the smallest value at the top. Its left and right sides need not be sorted.
Now it has a name Choose the promise you need.
Looking for an ordered key? Think search tree. Repeatedly taking the smallest? Think min-heap.
No pressure. Just try it.Does a min-heap promise its left side is smaller than its right?
1 / 4 A small step before this topic
Let’s picture it Only the smallest waiting item matters next.
Tasks cost 5,1,4. We need the cheapest task now, then the next cheapest after adding new tasks.
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.
Now it has a name Push and pop logarithmically.
Use a heap when priorities change incrementally and repeatedly sorting the entire collection would waste work.
No pressure. Just try it.Does iterating the internal heap array return sorted order?
1 / 4 A small step before this topic
Let’s picture it Count before ranking.
In [a,a,a,b,b,c], frequencies are a:3, b:2, c:1. The raw input order is not the priority.
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.
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.
No pressure. Just try it.Which heap root is useful when keeping the k largest frequencies?
1 / 4 A small step before this topic
Let’s picture it Several lists offer one front each.
Lists [1,4], [2,3], and [0,7] each expose their smallest remaining value.
One little change The global next value is among those fronts.
A min-heap chooses 0. After using it, only its list contributes a new front: 7.
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.
No pressure. Just try it.After popping one node, which list can offer a newly eligible node?
1 / 4 A small step before this topic
Let’s picture it One middle changes as values arrive.
After 2, median is 2. After 2,8 it is 5. After 2,5,8 it is 5.
One little change Split values into two halves.
A max-heap holds the lower half; a min-heap holds the upper half. Their roots touch at the middle.
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.
No pressure. Just try it.What invariant relates every lower-half value to every upper-half value?
1 / 4 Keep a connection for later.
Tap the bookmark on any post to find it here.