Computer Science is about writing programs to solve problems.
However, computers don’t understand everything, so when we try to solve problems, we humans need to express them in a way that a computer can understand.
The way of doing this is called computational thinking, which means we need to think like a computer.
To do this, programmers use several techniques to help break down problems into smaller problems that can be turned into code.
In this lesson, we’ll learn about:
Imagine you have been asked to cook dinner.
You have been told that:
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 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? 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 list, we can then remove the unnecessary items, and we are left with:
The process of stripping out unnecessary information from a problem is called ABSTRACTION.
This means that the program will focus only on the details needed to solve the problem.
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.
You need to keep decomposing the problem until you arrive at a series of steps that cannot be further broken down.
You should be able to stick all the individual pieces back together to make a complete program.
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 that 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:
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 no cars are coming at all?
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.
Decomposition is where a large problem is broken down into smaller problems.
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.
Tools we use to design algorithms are pseudocode and flowcharts.