Skip to Content
Design and implement mathematical algorithms - Maths Curriculum Companion - Department of Education & Training

## Teaching Context

### Victorian Curriculum

Design and implement mathematical algorithms using a simple general purpose programming language (VCMNA254)

VCAA Sample Program: A set of sample programs covering the Victorian Curriculum Mathematics.

VCAA Mathematics glossary: A glossary compiled from subject-specific terminology found within the content descriptions of the Victorian Curriculum Mathematics.

##### Achievement standards

Students solve problems involving the order, addition and subtraction of integers. They make the connections between whole numbers and index notation and the relationship between perfect squares and square roots. They solve problems involving all four operations with fractions, decimals, percentages and their equivalences, and express fractions in their simplest form.

Students compare the cost of items to make financial decisions, with and without the use of digital technology. They make simple estimates to judge the reasonableness of results.

Students use variables to represent arbitrary numbers and connect the laws and properties of number to algebra and substitute numbers into algebraic expressions. They assign ordered pairs to given points on the Cartesian plane and interpret and analyse graphs of relations from real data.

Students develop simple linear models for situations, make predictions based on these models, solve related equations and check their solutions.

## Teaching ideas

### Pseudo code

Tab Content

This activity is designed to introduce pseudo code and how it can be used to assist writing programming language.

Introduce pseudo code to students. Ask if any students have heard of pseudo code and if yes what they know about it. Discuss what pseudo code is and how it is used to describe a set of instructions that we can easily check before converting codes into programming language that a computer can understand. Introduce common notation used and describe what each one means.

Tab Content

Demonstrate pseudo code with an example. You may like to start with a flowchart if students are familiar with representing algorithms in flowcharts and then convert this into pseudo code.

Eg The algorithm finds the difference between two numbers.

OUTPUT = 3 (since a = 5 and b = 2 a - b = 5 – 2 = 3)

Now convert this into pseudo code (pseudo code is written vertically)

Tab Content

Ask students to have a turn writing their own pseudo code for multiplying two numbers (or any other operation). They can assign their own initial values and see if they get their intended output. You may like to ask for volunteers to display their pseudo code and let the class determine what the output is.

This provides an opportunity to discuss what is needed and how specific pseudo code needs to be to reach an output. With one step missing the output may be misunderstood or will not be able to be calculated, so it is important that students take their time to ensure all steps are listed.

Now present another algorithm written in pseudo code to the class that includes a condition.

E.g. START

SET a=12

IF a/4 is even

THEN OUTPUT ‘a is even’

ELSE OUTPUT ‘a is odd’

END IF

END

Ask students to pair up and discuss what the algorithm is instructing them to do and what the output would show. Ask students to write down what each line of the pseudo code means.

As a class see what responses the students decided on.

• What will the output be? (a is odd as 12/4 = 3)
• How did you reach this conclusion? (Calculate 12/4 and the answer is an odd number)
• Were there any steps in the code you didn’t understand? If so, which steps?
• Which instruction/s would need to be changed if we wanted a different output? (Change the initial value or change the operation a/4)

To finish off the activity ask students to write a pseudo code with a condition involved. Ask students to swap their code with another student to see if they can produce the desired output from their pseudo code.

### Outputs

Tab Content

This activity is designed to assist students reading pseudocodes and determine if the correct output has been determined.

Ask students to pair up and advise them that they will be checking pseudocodes to ensure the outputs are correct.

Provide students with several pseudocodes to ‘check’. It is recommended to have a variety of pseudocodes that show correct and incorrect outputs. Lastly discuss answers as a class and which pseudocodes the students think are incorrect and what the correct output should be.

### Using loops to dance

Tab Content

This activity is designed to highlight the benefit of using loops when there is a series of repetitive instructions.

Begin the lesson with an example that has a series of repetitive instructions (seeing example in teaching context – eating dinner). Ask students what might be challenging if we represented these instructions using pseudocode (students will hopefully identify that it will be a lot of repetition).

Introduce loops to the class. Loops are steps that are repeated a number of times in an algorithm. Loops assist in algorithms as they reduce the need for unnecessary steps.

Refer to the example you used at the beginning of the lesson (reference made to teaching context – eating dinner). Show how it could be rewritten using the notation for loops (WHILE) and discuss how using this notation will make repetitive instructions easier to write in code

Brainstorm other examples that have a series of repetitive instructions that would benefit from using a loop. For instance, a dance sequence, colouring in a picture or counting by the same interval.

Advise students that they will be learning a simple dance today. Ask them to spread out across the room. Provide students the dance instructions: have them on the whiteboard or screen for all students to see. Ask students to try the dance moves slowly at first and then speed up as they get familiar with the steps.

Clap, Clap, Clap

Hands behind head, Hands on waist, Hands behind head, hands on waist

Clap, Clap, Clap Pat head, touch toes,

Pat head, touch toes

Clap, Clap, Clap Clap, Clap, Clap

Hands behind head, Hands on waist, Hands behind head, hands on waist

Clap, Clap, Clap

Pat head, touch toes, Pat head, touch toes

Clap, Clap, Clap

Hands on shoulders

Once the students have run through the dance several times ask students to sit back down and discuss the dance steps

• Did you notice a loop or loops in the instructions?
• Where would a loop be of assistance?
• Would we be able to rewrite the instructions using loops? What would this look like?
• Would we be able to use the same loop for the different dance moves? Why/why not?

Ask students in pairs to rewrite the dance instructions using loops where appropriate. If time permits discuss where loops can be added and how the instructions can be rewritten otherwise, you may like to collect the revised instructions for assessment.

This teaching idea is taken from the Getting Loopy activity found on code.org.

### Using loops with pseudo code

Tab Content

This activity is designed to show students how loops can be written in algorithms using pseudo code.

Revise loops and how they are used in algorithms when a series of instructions need to be repeated. In pseudocode, the notation WHILE is used to indicate a condition that is repeated a certain number of times.

Show the class an example of a loop written in pseudo code (shown on left-hand side). Discuss with the class what each line means (shown on the right-hand side)

 START Start SET c = 3 Assign the initial value as 3 WHILE c <= 6 repeat the next step While c has a value less than 6 repeat the next step c= c+1 Add 1 to the value of c END WHILE Stop when c is no longer less than 6 OUTPUT c Write the final value of c END End

What will the output be?

Where is the loop?

After the 3rd loop the value is equal to 6 therefore we have repeated the loop too many times. We needed to stop after the 2nd loop. Therefore, the output is 5.

Here the loop sets a condition and tells us to repeat twice to achieve our output value.

Provide students with another example and ask them to explain the meaning of each line. Answers are shown in red.

What is the output? Where is the loop?

Output = sum = 11 (Note: 4th loop d is larger than 8 so we stop at the 3rd loop)

Now explain the task to students. They are going to use loops to write different pseudo codes to represent different algorithms and then create their own algorithms. Some ideas are listed but you may wish to use others. The examples are designed so that students select their own variables.

Pair up with another student.

Part 1: Write pseudo codes to represent the following algorithms

• Start at 1 and add 1 until the initial value is greater than 5.
• Start at 2, keep multiplying by 2 until the number is greater than 30

Part 2: Create two pseudo codes to represent two different algorithms. You must include a loop in each algorithm. When you are finished swap Part 2 with another pair and determine what the output is for each pseudo code. Compare your answer with the other pair and determine whether you found the right output.

Each pair can then answer these questions underneath where they have written their algorithms for Part 2.

• What did we learn from this activity?
• Did our pseudocode assist the other pair to determine the desired output?
• If not, have you identified how the pseudocode can be amended?

## Related content areas ###### Previous Level
Design algorithms involving branching and iteration 