Your concept feed
24 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 Where did we put the book?
Try “second shelf, first box.” We need two positions, not just one.
One little change Pick a row, then a column.
Python calls the second row 1. The first column is 0. So the book is at [1][0].
Now it has a name That’s a two-dimensional table.
Two labels find one cell. A third label could tell us which cupboard contains the table.
No pressure. Just try it.Two cupboards have the same shelves. What extra label helps?
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 Keep a small part of a row.
Our budget is 5. The values 2 and 3 fit together.
One little change One more makes it too much.
Add 4: the sum is 9. Remove from the left until it fits again.
Now it has a name That moving part is a window.
left edge
kept values
right edge
With nonnegative values, adding cannot lower the sum. That predictable change tells us which boundary to move.
No pressure. Just try it.Could adding a negative number make a too-large sum fit?
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 Order can expose structure.
Unsorted values [4,1,3,1] hide equal neighbors and make smallest-first processing awkward.
One little change Sort once, scan simply.
After sorting: [1,1,3,4]. Duplicates touch, boundaries become visible, and two pointers become possible.
Now it has a name Account for the price.
sort cost
simpler scan
reuse order
Comparison sorting usually costs O(n log n). It is worthwhile only when the simpler scan or repeated queries repay that cost.
No pressure. Just try it.Does sorting preserve original positions automatically?
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 Huge coordinates may have few distinct values.
Points lie at 10, 1,000,000, and 30. An array with a million cells wastes space.
One little change Sort unique coordinates.
Map 10→0, 30→1, and 1,000,000→2. Comparisons preserve their original order.
Now it has a name Ranks are not distances.
Compressed difference 2−0 does not mean the original points are two units apart. Keep original gaps when geometry or length matters.
No pressure. Just try it.What does coordinate compression preserve?
1 / 4 A small step before this topic
Let’s picture it Car and cat start the same way.
Write c, then a, just once. Split where the words become different.
One little change A prefix isn’t always a word.
If we only stored cart, reaching c-a-r is not enough to say car was stored too.
Now it has a name Mark where each word ends.
This shared-prefix tree is a trie. The word-end mark tells a whole word apart from just its beginning.
No pressure. Just try it.Only cart is stored. Does car count as a stored word?
1 / 4 A small step before this topic
Let’s picture it Neighboring substrings share most characters.
Windows abc and bcd overlap in b,c. Recomputing a numeric fingerprint from scratch repeats work.
One little change Remove, shift, add.
Subtract the outgoing character’s contribution, multiply the remaining fingerprint by the base, then add the incoming character.
Now it has a name A hash match is evidence, not equality.
Different strings can collide. Verify matching candidates or use collision-resistant engineering appropriate to the setting.
No pressure. Just try it.Does equal hash prove equal strings mathematically?
1 / 4 A small step before this topic
Let’s picture it A mismatch need not erase everything.
abab matched
suffix ab
prefix ab
Pattern abab has matched, then the next character differs. Its suffix ab is also a prefix we already know.
One little change The prefix table stores fallback length.
pattern position
border length
For each pattern ending, remember the longest proper prefix that is also a suffix.
Now it has a name Fallback without moving text backward.
text stays
pattern falls back
On mismatch, shorten the matched pattern using that table. Every text position advances once overall.
No pressure. Just try it.Why not restart the pattern at zero after every mismatch?
1 / 4 A small step before this topic
Let’s picture it Ask the same prefix question everywhere.
prefix
suffix at i
match length
For each position i, how many characters from s[i:] match the beginning of s?
One little change Reuse one rightmost matching box.
If i lies inside a known prefix-matching interval, copy a safe lower bound from the corresponding prefix position.
Now it has a name Extend only beyond known work.
reuse inside
compare beyond
Compare characters only after the reused match reaches the box edge. The right boundary moves at most n times.
No pressure. Just try it.What does Z[i] measure?
1 / 4 A small step before this topic
Let’s picture it Every palindrome has a center.
In abac, aba expands around b. Even palindromes center between characters.
One little change Transform to one center type.
Separators turn aba into ^#a#b#a#$, so odd and even original palindromes both have character-like centers.
Now it has a name Mirror inside the rightmost palindrome.
A center inside a known palindrome can reuse its mirror radius, clipped by the right edge, then expand beyond it.
No pressure. Just try it.Does the mirrored radius always copy completely?
1 / 4 A small step before this topic
Let’s picture it Each position starts a suffix.
banana
anana
nana
ana, na, a
banana has suffixes banana, anana, nana, ana, na, a. Sorting them groups shared beginnings.
One little change Ranks can double known prefixes.
rank first half
rank second half
First rank one character. Then sort suffixes by the pair of ranks for their first 2ᵏ characters.
Now it has a name Neighbors reveal repeated substrings.
sorted suffixes
neighbor LCP
The longest common prefix of adjacent sorted suffixes gives repeated-prefix information across the text.
No pressure. Just try it.Why can two ranks represent a doubled prefix?
1 / 4 Keep a connection for later.
Tap the bookmark on any post to find it here.