Computer Science Grade 4 20 min

Counting Steps: Measuring Algorithm Efficiency

Introduce the idea of counting the number of steps an algorithm takes to complete.

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Define an algorithm's 'step' as a single action. Count the total number of steps in a simple, sequential algorithm. By the end of a this lesson, students will be able to explain that fewer steps usually means a faster, more 'efficient' algorithm. Count the steps in an algorithm that uses a simple loop. Compare two different algorithms for the same task and identify which one is more efficient by counting their steps. Identify the 'worst-case' number of steps for a searching algorithm. Imagine you have to find your favorite red sock in a drawer full of socks. What's the fastest way to do it? 🧦 Let's find out by counting our steps! In this lesson, we'll learn how to measure how fast our computer programs a...
2

Key Concepts & Vocabulary

TermDefinitionExample AlgorithmA list of step-by-step instructions to finish a task, just like a recipe for baking cookies.An algorithm to make a peanut butter sandwich: 1. Get two slices of bread. 2. Spread peanut butter on one slice. 3. Put the slices together. StepA single action or instruction in an algorithm.In a robot's algorithm, 'move forward one space' is one step. 'Turn right' is another single step. EfficiencyA measure of how fast an algorithm is. An algorithm with fewer steps is more efficient.An algorithm with 5 steps is more efficient than an algorithm with 20 steps to do the same job. InputThe information or items an algorithm starts with to do its job.If our algorithm is to find the tallest person in a class, the 'input' is the list of al...
3

Core Syntax & Patterns

The One-Action Rule 1 Action = 1 Step Every single, simple command in an algorithm counts as one step. Use this to count the total work your algorithm does. The Loop Rule Steps Inside Loop x Number of Repeats To find the total steps for a loop, count the number of actions *inside* the loop, and then multiply that by how many times the loop repeats. The Efficiency Rule Fewer Steps = More Efficient When comparing two algorithms that solve the same problem, the one that takes fewer steps in the worst-case is considered more efficient.

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
An algorithm searches for a green jellybean in a jar of 25 jellybeans by picking them out one by one. What is the difference in the number of steps between the best case and the worst case?
A.24
B.1
C.25
D.0
Challenging
An algorithm to greet a person: 1. Check if you know their name. 2. If you do, say 'Hello, [Name]!'. 3. If you don't, say 'Hello, nice to meet you!'. What is the total number of steps performed for one person?
A.Always 3 steps
B.It can be 2 or 3 steps
C.Always 1 step
D.Always 2 steps
Challenging
To find out if anyone in a group of 10 friends has a birthday in June, an inefficient algorithm is to ask each friend for their birthday month, even after you find one. What is a more efficient algorithm?
A.Stop asking as soon as you find one person whose birthday is in June
B.Ask only the first 5 friends
C.Ask every friend for their birthday month, no matter what
D.Ask each friend twice to be sure

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from Algorithm Adventures: Making Code Run Faster

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.