Search Sreeni's Insights

Filter by content type
technical April 5, 2011 6 min read

What is computational thinking? - Part 1

This article introduces computational thinking through decomposition, pattern recognition, abstraction and algorithm design, showing beginners how the same pillars help solve a grocery billing problem.

Share:

What is computational thinking? - Part 1

Learning the syntax of a programming language is the easy part, there are plenty of books and tutorials for it and anybody can learn to write a loop in a week. The hard part is to look at a messy real-world problem and know where to start. Two people can learn the same language, one will build a working solution and the other will be stuck with an empty editor, and the difference is not the language, it is the way of thinking. In the previous series, we discussed how computers solve real-world problems, what is a program and how a program is executed by the computer. In this series, I share how to think like a programmer. In this article, we are going to see what is computational thinking and its four pillars, decomposition, pattern recognition, abstraction and algorithm design.

Thinking Like a Programmer series:

  1. What is computational thinking? (this article)
  2. How to solve problems with algorithms? - Part 2
  3. How data and information are represented in a computer? - Part 3
  4. What are data structures? - Part 4
  5. What are programming paradigms? - Part 5

TL; DR Summary

  • Computational thinking is a way of solving problems so that the solution can be carried out by a computer, or even by a human.
  • It is not about thinking like a computer, it is about thinking clearly so that a computer can follow.
  • Decomposition - Break a big problem into smaller problems which are easy to solve.
  • Pattern recognition - Find the similarities, so we can solve once and reuse many times.
  • Abstraction - Keep only the details which matter and ignore the rest.
  • Algorithm design - Write the step by step solution for each part.
  • These four pillars are used together and iteratively, not one after the other only once.

Common Challenges

The problem looks too big

When a beginner hears “build a billing system for a grocery shop”, it looks like one huge thing. Where to start? Barcode, stock, discount, printing, tax, everything comes into the mind at the same time. As a result of this, either we start typing code randomly or we give up before starting. Both are not good.

Too many details

Real-world problems come with lots of details. The customer’s name, the colour of the bag, the time of the day, the brand of the printer. Some of these details are important for the solution and most of them are not. When we try to handle everything, the program becomes complex, slow to build and hard to change.

Solving the same thing again and again

Without stepping back to look at the problem, we will not notice that many parts are actually the same. We write the code for the rice item, then again for the sugar item, then again for the oil item, and when a rule is changing, we have to change it in many places, otherwise some bills will be correct and some will be wrong.

What is computational thinking?

Computational thinking is the thought process of formulating a problem and its solution in a way that the solution can be carried out by a computer.

In simple terms, computational thinking is thinking clearly and in steps. It is not about thinking like a computer, a computer doesn’t think at all, as we discussed in the previous series. It is about breaking down the problem and explaining the solution so clearly that even a machine with no common sense can follow it. The term became popular after Jeannette Wing’s article “Computational Thinking” in 2006, where she said it is a fundamental skill for everyone, not only for computer scientists.

Basically, computational thinking has four pillars. The following diagram depicts these four pillars.

Four pillars of computational thinking
Four pillars of computational thinking

Let us discuss each pillar with our grocery shop billing system.

Decomposition

Decomposition is breaking down a complex problem into smaller parts, which are easier to understand, solve and test.

Simply put, it is like eating a big cake, we don’t eat it in one bite, we cut it into pieces. Our billing system can be broken down into few smaller problems, read the items, calculate the total, apply the discount and print the bill. Again, each of these can be broken down further, read the items means scan the barcode and find the price.

The following diagram depicts how the billing system is decomposed into smaller parts.

Decomposing a billing system
Decomposing a billing system

Keep breaking down until each part is small enough that you know how to solve it. “Build a billing system” is too big, “find the price of an item from its barcode” is small enough to start. It is also helpful when we work in a team, different people can work on different parts at the same time.

Pattern recognition

Pattern recognition is finding the similarities or common behaviour among the smaller problems or with the problems we have solved before.

In our billing system, rice, sugar and oil are different items, but for the bill, they all follow the same pattern, price multiplied by quantity. It means, we don’t need separate logic for each item, we solve it once and use it for every item, whether the customer buys 3 items or 300 items.

Patterns are not only inside one problem. A bus ticket system, a restaurant bill and an electricity bill are all following the same pattern, read some values, calculate, apply the rules and print. Once you solved one, the second one is much easier. This is the reason experienced programmers look faster, most of the time they are recognizing a pattern they have seen before.

Abstraction

Abstraction is focusing only on the important information for solving the problem and ignoring the details which are not relevant.

A city map is a good example of abstraction. It shows roads and places, but it doesn’t show every tree and every house, otherwise it is useless for finding the way. For our bill, the important details of an item are name, price and quantity. The colour of the packet, the factory where it is made or the shelf where it is kept are not needed for billing, so we ignore them.

Be mindful that what is important depends on the problem. For the billing, the shelf number is not needed, but for a stock management system, the same shelf number may be very important. There is no fixed list of right details, it depends on what we are solving. Keep this pillar in mind, in the Object-Oriented Thinking series, the same abstraction becomes the first principle of object-oriented design.

Algorithm design

Algorithm design is creating the step by step instructions to solve each part of the problem.

Once we decomposed the problem, found the patterns and kept only the important details, we can write the steps. We discussed what is an algorithm and its properties in the previous series, refer the Part 1 for more information.

Example:

The algorithm for the “Calculate total” part, using the pattern we found,

Step 1: Set total to 0
Step 2: For each item in the bill
Step 3:     Add (price * quantity) to total
Step 4: Return total

Notice that this algorithm doesn’t know about barcodes or printers, those are the other parts. Each part has its own small algorithm and together they solve the big problem.

How these pillars work together?

These four pillars are not steps to be done only once in a fixed order. We decompose, then we notice a pattern, then we abstract, then while writing the algorithm we realize one part is still too big, so we decompose again. We must travel through these pillars iteratively until each part is clear.

Most importantly, computational thinking is not only for programming. Planning a wedding, packing for a trip or preparing for an exam, we use the same thinking, break it down, find the patterns, focus on what matters and plan the steps. I have experienced many times in my life, a clear plan on paper saves lot of time later, I hope for you too.

Wrap up

In this article, we have looked at the common challenges in starting with a problem, what is computational thinking and its four pillars, decomposition, pattern recognition, abstraction and algorithm design. I really appreciate that you took the time to read this article and I hope this article provided you some insights into thinking like a programmer. In the next article, I will walk you through how to solve problems with algorithms, using pseudocode, flowcharts and a simple way to compare which algorithm is better.

Related Posts