🧠 Thinking Like a Programmer: Computational Thinking

4th Grade 💻 Coding

Programmers don’t just write code — first, they think in a certain way. That way of thinking is called computational thinking, and you can use it even without a computer: for homework, cleaning your room or planning a trip. In this lesson we meet its four tools and play a game that shows how much it matters to pick a smart algorithm.

Free · US Letter · no sign-up
Google Classroom Save to Pinterest Email me

Decomposition: small pieces

A big problem can seem scary. “Build a game” — where do you even start? The first tool is decomposition: you split the problem into small parts, and those parts into even smaller parts, until each part is simple enough to solve. A game breaks down into a character that moves, obstacles, a score and a game-over screen. “A character that moves” breaks down into moving right, moving left and jumping.

We break down problems all the time without noticing. Planning a birthday party breaks down into invitations, food, games and decorations. A history project breaks down into choosing a topic, finding sources, writing and checking. The advantage: you can solve each small part on its own, split them up among teammates and test each one separately.

Patterns and abstraction

The second tool is pattern recognition: looking for what’s similar. If you’ve already written code that moves the player to the right, moving left is almost the same — just with a minus sign. If all the enemies in a game move the same way, you can write the movement once and use it for all of them. People who spot patterns save work, and in programming, they turn patterns into loops and functions.

The third tool is abstraction: deciding what’s important and ignoring the rest of the details. A subway map is a great example: it doesn’t show every building and tree, or even exact distances — only the stations and their order, because that’s all a rider needs. In a computer soccer game, too, you don’t program every blade of grass; a green field, lines, players and a ball are enough.

Algorithms: the fourth tool

The fourth tool is building an algorithm — an exact list of steps that solves the problem. And here’s where it gets interesting: for the same problem, some algorithms are better than others. The “Guess the Number” game shows this nicely. I think of a number between 1 and 100, and you guess; after each guess I say “higher” or “lower.”

One algorithm: guess 1, then 2, then 3… — in the worst case, that takes 100 guesses. A smarter algorithm: always guess the middle of the range. Start with 50; if I say “higher,” the range is 51 to 100, so you guess 75, and so on. With every guess, half of the possibilities disappear, so you always find the answer in 7 guesses or fewer. This method is called binary search, and computers use it to search huge sorted lists quickly.

Sorting and testing

Another example is sorting — putting things in order. Try sorting ten numbered cards: you could look for the smallest card each time and set it aside, or you could take the cards one by one and slide each one into the right place among the cards you’ve already sorted — the way people arrange cards in their hand. Both methods work, but when there are a million items, the difference in speed between sorting methods is huge. Computer scientists have been inventing and comparing algorithms like these for decades.

And the last step of every solution is testing: Does the algorithm work? Even in the extreme cases — an empty list, a single number, all the numbers the same? Computational thinking isn’t only for computers. It’s an organized way to solve any problem: break it down, look for patterns, focus on what matters, plan the steps — and test. If you practice it, it will help you in any job.

Key facts

  • Computational thinking has four tools: decomposition, pattern recognition, abstraction and algorithms.
  • Decomposition means splitting a big problem into small parts that are easy to solve.
  • Abstraction means focusing on what’s important and ignoring extra details, like a subway map does.
  • With binary search, you can find a number between 1 and 100 in 7 guesses or fewer.
  • Sorting means putting items in order, and there are many methods that work at different speeds.

Quick quiz

  1. What is decomposition in computational thinking?

  2. What is pattern recognition?

  3. Which example describes abstraction?

  4. At most, how many guesses do you need with binary search for a number between 1 and 100?

  5. What is the first guess in a binary search between 1 and 100?

  6. What is sorting?

  7. Why does it matter to choose a smart algorithm?

  8. What is the last step of every solution?

💭 Think and talk about it

  1. Break down “clean my room” into at least five parts. Which part could you break down even more?
  2. Play “Guess the Number” with a friend using binary search. Did you always get it in 7 guesses or fewer?
  3. Find an example of abstraction in real life: a map, a symbol or a drawing that leaves out details on purpose.

Questions kids ask

What is computational thinking?

A way to solve problems the way computer scientists do: break a problem into parts, spot patterns, focus on what matters (abstraction) and build an algorithm — a list of steps. It’s useful even without a computer, in any job.

What is binary search?

A way to search a sorted list: check the middle, and depending on the answer, keep going only in the half that fits. With each step, half the possibilities are left, so even in a list of a million items you find the answer in about 20 steps.

Is computational thinking taught in school?

In many countries, including the United States, there are programs that bring computational thinking and coding into elementary school. You can practice at home too — with logic games, puzzles and coding in Scratch.

🔎 Ask Thinkapedia another question