Chapter 1. Algorithms and Computational Thinking FREE
1.1 What is an algorithm?
An algorithm is a set of step-by-step instructions that solves a problem or completes a task. You already use algorithms every day without thinking about it. A recipe is an algorithm. The instructions for building a model are an algorithm. Even the steps of your morning routine form an algorithm: wake up, wash, get dressed, eat breakfast and pack your bag.
In Coding and Robotics we write algorithms for computers and robots. A computer follows instructions exactly as they are given. It cannot guess what you meant. This is why the steps of an algorithm must be clear, complete and in the correct order.
1.2 Computational thinking
Before we can write a good algorithm, we must think about the problem in a structured way. This is called computational thinking, and it has four steps:
- Decomposition: break the big problem into smaller parts that are easier to solve.
- Pattern recognition: look for similarities between the parts. If two parts look alike, the same solution might work for both.
- Abstraction: ignore the details that do not matter and focus on the information that does.
- Algorithm design: plan the steps that solve the problem, one by one.
Here is an example. Suppose your class is planning the year-end party. Decomposition breaks the task into food, games and invitations. Pattern recognition shows that the food list and the invitation list both need the number of learners in the class. Abstraction says the colour of the plates does not matter, but the number of learners does. Algorithm design puts the steps in order: count the learners, make the lists, hand out the tasks and check everything before the party.
1.3 Order matters
The steps of an algorithm must be in the correct order. Think about making tea. If you pour the water into the cup before you boil it, you get cold tea. The steps were right, but the order was wrong. A computer does not fix mistakes like this on its own, it carries out the steps exactly as you gave them.
1.4 Flowcharts: drawing an algorithm
A flowchart is a diagram of an algorithm. Each shape has its own meaning. A rounded shape, such as an oval, shows where the algorithm starts and stops. A rectangle shows a process, an action step that must be carried out. Arrows show the direction of the flow: the order in which the steps happen. In a later chapter you will also meet the decision shape, which lets a flowchart ask a question and choose between paths.
1.5 Algorithms, computers and robots
In block-based coding you snap instruction blocks together to build a program. Each block is one step of the algorithm. Later in the year you will compare this with line-based coding, where you type the instructions as text. Robots work on the same pattern: they receive input from sensors, process it according to the algorithm, and produce output such as movement, light or sound.
Summary
- An algorithm is a set of step-by-step instructions that solves a problem or completes a task.
- Computational thinking has four steps: decomposition, pattern recognition, abstraction and algorithm design.
- The order of the steps in an algorithm is important.
- A flowchart draws an algorithm with rounded shapes (Start and Stop), rectangles (processes) and arrows (flow).
- Computers and robots follow instructions exactly as they are given.