Computational Thinking

Computer Science is all about writing programs to solve problems. The thing is that computer systems are only as good as the code we write for them.

Computers don’t understand everything, so when we are trying to solve problems, we as humans need to put the problems into a way that a computer can understand.

The way of doing this is called Computational Thinking and it basically means we need to think like a computer. In order to do this, there are several techniques that programmers use to help break down problems into smaller problems that can be turned unto code.

In this lesson, we’ll learn about:

  1. Abstraction
  2. Decomposition
  3. Algorithmic Thinking
Media Attachments: Presentation Video

1. Abstraction

Imagine you have been asked to cook dinner.

You have been told that:

  • Your guests are John, Jane, Hamza and Ali.
  • They are all 22 years old.
  • Ali is allergic to peanuts and shellfish.
  • John and Jane are married. Hamza and Ali are single.
  • Ali is Tee Total.
  • Jane is Vegetarian.

Now in this list of information, there is some information that is absolutely necessary for you to be able to cook dinner, and some that is not.

Looking at the above list you should have identified the following:

Your guests are John, Jane, Hamza and Ali. Is this necessary? YES – so you can identify your guests.

They are all 22 years old. Is this necessary? Is this necessary? NO – it does not affect your menu choices.

Ali is allergic to peanuts and shellfish. Is this necessary? YES – you cannot have any of these items on the menu.

John and Jane are married. Hamza and Ali are single. Is this necessary? NO – it does not affect your menu choices.

Ali is Tee Total. Is this necessary? YES – you cannot use any recipe that involves alcohol.

Jane is Vegetarian. Is this Necessary? YES – you’ll want to avoid meat in your menu.

From the above list we can then remove the unnecessary items and we are left with:

  • Your guests are John, Jane, Hamza and Ali.
  • Ali is allergic to peanuts and shellfish.
  • Ali is Tee Total.
  • Jane is Vegetarian.

The process of stripping out un-necessary information from a problem is called ABSTRACTION.

It means the program will focus only on the details needed to solve the problem.

Further Thought

Think of the register program being used in your school. What information about you is necessary and unnecessary?

2. Decomposition

Let’s stick with the making dinner scenario.

You’ve stripped out all the unnecessary details, now you need to make dinner.

You could try and cook the whole thing at once, but this would be challenging.

You might decide to break it down into a starter, a main course and a dessert.

You might decide that as the dessert is cake and ice cream, you can make it the day before and leave it in the fridge.

You might then break the main course down further into a meat course and vegetable course, so Jane is taken care of.

However, in doing so you realise you don’t have enough pots and pans, so a hidden problem has been identified.

This process, of taking a larger problem and breaking it down into smaller, more manageable problems is called DECOMPOSITION.

It also helps you to spot other problems you might encounter.

Decomposing the Making Dinner Problem
Figure 1 – Decomposing the problem of making dinner into smaller problems.

You need to keep decomposing the problem until you arrive at a series of steps that cannot be broken down any further.

You should be able to stick all the individual pieces back together to make a complete program.

Further Thought

Imagine you have been asked to build a Student Planner program to use in your school or college to help students view their timetable.

Can you break the problem down into a series of smaller problems that cannot be broken down any further? Can you identify any hidden problems?

3. Algorithmic Thinking

An algorithm is a set of steps that can be followed again and again to solve a problem.

The idea is that an algorithm can be written using special tools called Pseudocode or Flowcharts, and then the algorithm can be built in the programming language of choice (Python, C#, VB.NET, Pascal, C++, Java, etc.) and it will work.

If you have ever assembled any bookcases from Ikea, you will have been given an instruction sheet which contains the algorithm for assembling that furniture.

Anybody could follow that instruction sheet and then build that particular bookcase, and this should work repeatedly.

That instruction sheet would not work for a coffee table though.

Let’s look at an algorithm for crossing a road:

  1. Stand and wait at the traffic lights
  2. Push the pedestrian button
  3. Wait
  4. When the Little Man goes Green
  5. Cross the road

Is this algorithm correct? Could you follow these rules every time you cross the road?

Well, not really.

For example, this algorithm doesn’t take into account what you should do if the pedestrian button has already been pressed?

Also, what happens if there are no cars coming at all?

Further Thought

Can you think of any other ways in which the crossing the road algorithm would need to be modified to deal with EVERY circumstance?

Lesson Summary

So to summarise what we’ve learnt in this lesson:

  • Computational thinking is when a programmer approaches a problem in a way that a computer might understand.
  • Abstraction is where any unnecessary details are removed from the initial problem.
  • This means that you are left with only that which the program needs to do.
  • Decomposition is where a large problem is broken down into smaller problems.
  • This helps you identify any other hidden problems from the outset.
  • By solving all of the smaller problems, you should be able to put them together to solve the original problem.
  • An algorithm is a set of rules that can be repeatedly applied to solve a problem.
  • An algorithm does not depend on a programming language.
  • Tools we use to design algorithms are pseudocode and flowcharts.