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:
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 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:
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.
Think of the register program being used in your school. What information about you is necessary and unnecessary?
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 broken down any further.
You should be able to stick all the individual pieces back together to make a complete program.
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?
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:
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?
Can you think of any other ways in which the crossing the road algorithm would need to be modified to deal with EVERY circumstance?
So to summarise what we’ve learnt in this lesson: