Computer Science
Grade 7
20 min
Lesson 8: Algorithms Revisited: Combining the Pillars
Reinforce the concept of algorithms and how they integrate with decomposition, pattern recognition, and abstraction.
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Define the three pillars of programming: sequence, selection, and iteration.
Identify sequence, selection, and iteration within a given algorithm.
Combine sequence, selection, and iteration to solve a multi-step problem.
Decompose a complex problem into smaller sub-problems that can be solved using the three pillars.
Write pseudocode that correctly uses nested control structures, such as a loop inside a selection.
Trace the execution of an algorithm that combines all three pillars to predict its output.
Ever followed a recipe that had a step like, 'for each cookie, bake for 10 minutes, but IF it's a large cookie, bake for 12'? You were combining the pillars of algorithms! 🍪
Just like buildings are made from pillars, beams, and walls, comp...
2
Key Concepts & Vocabulary
TermDefinitionExample
AlgorithmA step-by-step set of instructions or rules to be followed to solve a problem.A recipe for baking a cake is an algorithm. You must follow the steps in order to get the correct result.
SequenceThe pillar of programming where instructions are executed one after another, in the specific order they are written.To make a sandwich: 1. Get two slices of bread. 2. Put cheese on one slice. 3. Put the other slice on top.
SelectionThe pillar of programming that allows for choices. A certain block of code is run only IF a specific condition is met. Also known as a conditional.IF it is raining, THEN take an umbrella. You only take the umbrella if the condition (raining) is true.
IterationThe pillar of programming that repeats a set of instructions. This is often called a...
3
Core Syntax & Patterns
The Combined Algorithm Pattern
Setup (Sequence) -> Main Process (Iteration with nested Selection) -> Final Result (Sequence)
Use this pattern to structure your thinking. First, set up your variables (like a score or a counter). Then, use a loop to process data, making decisions inside the loop. Finally, display the final result after the loop is done.
Nesting Logic
An `IF` statement can go inside a `LOOP`. A `LOOP` can go inside an `IF` statement.
Nesting is key for complex tasks. To check every item in a backpack for a specific book, you use a loop to go through the items and an `if` statement inside the loop to check if an item is the book you're looking for.
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
A programmer's code to count even numbers in a list always outputs 0 or 1. What is the most likely cause of this error?
1. SET even_count = 0
2. FOR each number in list
3. SET even_count = 0
4. IF number is even THEN
5. even_count = even_count + 1
6. END IF
7. END FOR
A.The counter is being reset to 0 inside the loop.
B.The IF statement condition is incorrect.
C.The loop is an infinite loop.
D.The program is not using selection.
Challenging
You need to write an algorithm that goes through a list of temperatures and displays 'Warning!' for any temperature that is BOTH above 30 degrees AND below 40 degrees. Which pseudocode structure is correct?
A.LOOP through temperatures: IF temp > 30 THEN IF temp < 40 THEN DISPLAY 'Warning!'
B.LOOP through temperatures: IF temp > 30 THEN DISPLAY 'Warning!'. IF temp < 40 THEN DISPLAY 'Warning!'
C.IF temp > 30 THEN LOOP through temperatures: IF temp < 40 THEN DISPLAY 'Warning!'
D.LOOP through temperatures: IF temp > 30 OR temp < 40 THEN DISPLAY 'Warning!'
Challenging
What is the fundamental difference in outcome between an algorithm with `LOOP ( IF )` versus one with `IF ( LOOP )`?
A.There is no difference; they produce the same result.
B.`IF ( LOOP )` is not a valid structure in programming.
C.`LOOP ( IF )` makes a decision for each item. `IF ( LOOP )` makes one decision and then may or may not perform the entire loop.
D.`LOOP ( IF )` is less efficient than `IF ( LOOP )`.
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free