Linear Algorithms
In a linear algorithm every command is carried out in order, once. Using everyday and calculation tasks, we learn to write linear algorithms.
All topics (4 of 11)
Chapter 1. Algorithm Basics
Chapter 2. Programming in Scratch
Chapter 3. Project Work
A linear algorithm is one whose commands are carried out from top to bottom, one after another, each exactly once. It has no condition checks and no repeats. Many everyday actions are linear: brushing teeth, packing a school bag or washing hands.
An example is an algorithm for brushing teeth. 1) Take the toothbrush. 2) Put toothpaste on it. 3) Brush your teeth for 2 minutes. 4) Rinse your mouth. 5) Put the brush back. The order of commands matters: if you rinse your mouth before putting on the paste, the result is different.
Linear algorithms appear in calculations too. To find the area of a rectangle, we enter its sides a and b, then calculate S = a * b and output the result. All the steps of this algorithm are carried out in order.
In a flowchart a linear algorithm can be drawn from top to bottom with a single arrow. After writing an algorithm, check it by hand on an example. For instance, if a = 4 and b = 5, the result should be S = 20.
Key takeaways
- In a linear algorithm commands run in order, once each.
- It has no condition checks and no repeats.
- The order of commands affects the result.
- A finished algorithm should be checked by hand on an example.
Practice tasks
- Write a linear algorithm of 5–6 steps for having tea with bread or for packing a school bag.
- Describe in words and as a flowchart the algorithm for the perimeter of a square,
P = 4 * a. - Write an algorithm for the area of a triangle with base a and height h. Check the result for a = 6, h = 4.
Review questions
Test yourself: think first, then reveal the answer.
1Which algorithm is called linear?Show answerHide answer
An algorithm whose commands run one after another, once each.2What is `S = a * b` when a = 3 and b = 7?Show answerHide answer
21.
0 of 11 topics completed
Sign in to mark