Post on: 2024-12-23Last edited: 2026-6-12Words 658Read Time 2 min

type
Post
status
Published
date
Dec 23, 2024
slug
learning-algorithm
summary
Using linked-list insertion and binary-tree traversal as examples, this post argues that algorithm learning works better when you draw the structure, simulate the steps, explain the invariant, and only then write code.
tags
Reflection
Algorithm
category
Essays
icon
password
paired_with
1651d487-a2a1-803d-b29f-c9c77dc93e9e
lang
translation_locked
source_hash
74f2570993d08dab473a51803efa75ed606eaf964c12833f7f004ee37d71dc4e
💭
A few days ago I read an ACM Queue article called Teaching Algorithmic Thinking. One sentence stuck with me: when learning algorithms, building the way of thinking matters much more than memorizing the final solution. Around the same time, I saw @Digital Nomad Samuel explaining linked-list insertion on Douyin. His explanation was basically pointing at the same idea. The two things landed together, so I wanted to write down the thought.

One Problem, Two Ways To Teach It

Take linked-list insertion. The traditional explanation often gives you two lines of template code:
You copy it, the answer passes, and it feels like you learned the pattern. But the next time the problem becomes “insert at position k,” “insert into a doubly linked list,” or “insert with a sentinel node,” you get stuck again, because you never really asked why those two lines were written in that order.
Samuel’s explanation was different. He drew the linked list on a whiteboard, connected the nodes with arrows, and then made you move the arrows yourself: which pointer should be broken first, which pointer should be connected later, what happens if the order is reversed, and which part of the list disappears if you cut the wrong edge. After you draw it yourself, those two lines of code become obvious. They are not a rule to memorize. They are just the text version of the picture in your head.
That is the small but important difference: either code is handed to you as the conclusion, or code becomes the last step of a thinking process you have already walked through.

How I Used To Learn It Wrong

I made this mistake for a long time. When I first learned binary-tree traversal, I treated preorder, inorder, and postorder as three separate things to memorize:
I remembered the sentence “inorder means left, self, right; preorder moves self to the front; postorder moves self to the end.” That was enough to pass some practice problems. But when I met graph traversal, the memorized rule did not transfer at all, because I had not realized these traversals are variations of the same thing.
The underlying idea is just “recursively walk through the whole structure.” The only difference is when you decide to do something with the current node. That can be explained in one sentence, but I spent months memorizing it as separate tricks.

How I Learn New Things Now

I do not want to dress this up as “systems thinking” or “building a knowledge framework.” For me it comes down to three concrete habits:
  1. Draw first, read code later. When learning a new data structure, I first draw it on paper and manually simulate insert, delete, or search. Code comes after the shape is clear.
  1. Force myself to explain it. Explain it to a classmate, a camera, or just the air. If I can explain it cleanly, I probably understand it. If I get stuck at one step, that is the part I do not understand yet.
  1. Group problems by pattern instead of memorizing individual questions. Binary-tree traversal and graph DFS are cousins. Linked-list reversal and stacks rhyme with each other. Sliding windows and two pointers often share the same mental move. When I see a new problem, I first ask: what old problem does this feel like?

A Small Map For Binary Trees

Bottom Line

The more I learn, the less I believe in “algorithm talent” as some mysterious fixed trait. A lot of the difference comes from whether someone helps you break through the invisible layer between code and the idea behind it.
If you are stuck on algorithms and grinding problems without feeling any progress, do not just keep grinding. Find a teacher or video that explains the thought process clearly, or draw the problem twice on a whiteboard yourself. That will often help more than forcing through ten more problems.

References


Loading...
What Does “Compiling Shaders” Mean in Games?

What Does “Compiling Shaders” Mean in Games?

A plain-language explanation of shader compilation: what shaders are, why GPU-specific machine code must be built locally, how graphics APIs changed the workflow, and why the first launch can take several minutes.


Auto-Scrolling AI Chats: How to Read User Intent

Auto-Scrolling AI Chats: How to Read User Intent

Auto-scroll in an AI chat is not just scrollTop. It needs intent signals, a follow/free state machine, handling for programmatic scroll events, virtualization, and mobile edge cases.


Announcement
This site is still updating…