topic badge
AustraliaVIC
Level 10

10.08 Flow charts

Lesson

Flow charts

Flow charts are diagrammatic ways to represent a list of actions that happen and the order they happen in.

To introduce the idea we will look at simple flow charts that use just 3 different shapes.

Ovals are used to show the beginning and end.

1 oval labelled START and 1 oval labelled  END.

Rectangles are used to state actions.

This image shows 6 rectangles that state   actions. Ask your teacher for more information.

Diamonds are used to indicate decisions that need to be made. You can think of these as questions.

This image shows 4 diamonds with questions inside them. Ask your teacher for more information.
This image shows a flow chart with ovals and rectangles. Ask your teacher for more information.

We connect these shapes with arrows to show the order we move through the flow chart.

Can you see what this flow chart is describing? We read the flow chart by starting at the START and following the arrows. You do the ACTIONS that are described until you reach the END.

This is an example of a linear sequence, it moves from beginning to end in one straight line. There are no decisions in this flow chart, just a sequence of steps to undertake.

This particular flow chart is describing one of the multiplication strategies we can use if we want to multiply by 5. The strategy is to start with the number, then multiply by 10 and then halve.

So to multiply 7 by 5 we can follow the flow chart:

This image shows a flow chart for multiplying by 5. Ask your teacher for more information.

Examples

Example 1

What is the output of this algorithm if the input is 4?

This image shows a flow chart with linear sequence. Ask your teacher for more information.
Worked Solution
Create a strategy

Use the given number as the input and follow each instruction in the flow chart.

Apply the idea
\displaystyle \text{Input}\displaystyle =\displaystyle 4Input the number
\displaystyle 4^2\displaystyle =\displaystyle 16Square the number
\displaystyle \dfrac{16}{2}\displaystyle =\displaystyle 8Divide the number by 2
\displaystyle \text{Output}\displaystyle =\displaystyle 8Output the number
Idea summary

A linear sequence is a flow chart that moves from beginning to end in one straight line. There are no decisions, just a sequence of steps to undertake.

Branches

Whenever we need to make a decision our flow chart branches out. Check out this flow chart.

This image shows a flow chart with branches. Ask your teacher for more information.

This flow chart has a decision, remember that the decisions are in the diamonds. The answer to a decision can be yes/no, or true/false etc. In this case, our TRUE answer resulted in an action and the FALSE answer resulted in the Stop command.

We could introduce an action after the no answer if we wanted to. What sort of actions could that be? What actions suit this context?

Because the decision has a yes or no answer, this creates what we call a branch in our flow chart.

Examples

Example 2

What is the output of this algorithm if the input is A=2 and B=5?

This image shows a flow chart with branches. Ask your teacher for more information.
Worked Solution
Create a strategy

Use the given numbers for A and B and follow the flow chart.

Apply the idea
\displaystyle A,\,B\displaystyle =\displaystyle 2, 5Input A=2 and B=5
\displaystyle \text{Is } 2>5\displaystyle =\displaystyle \text{No}Decide if A>B
\displaystyle C\displaystyle =\displaystyle 5-2Find C=B-A
\displaystyle \text{Output}\displaystyle =\displaystyle 3Output C
Idea summary

If a decision has a yes or no answer, this creates a branch in our flow chart.

SET, PRINT and Loops

In some flow charts we might want to PRINT, the number or answer. This could be on a computer screen, on a piece of paper or just to have the person write the number down in their book.

This image shows a flow chart with special action. Ask your teacher for more information.

This flow chart says to select a number, add 5 and then print the answer.

Sometimes we set a word to mean "whatever number we chose". For example, I could say SET \text{NUMBER}=5, and it would mean that the word number is always understood to be the value of 5. At least until it is set as another value.

The final thing we will look at in this section is a loop. Just like when you make a loop out of wire and you can trace your finger around and around the loop, so too loops in algorithms mean we can go around and around, until the code tells us to stop.

Follow this flow chart through from the START and determine what it is trying to achieve.

This image shows a flow chart with a loop. Ask your teacher for more information.

What did you get after following this flow chart? The statement "SET number = 1" sets the value of number to be 1. But then the statement "SET number = number +1" increases the value of number by 1.

You would have PRINTed (written down) the numbers from 1 up to 10 on your page, one at a time as you were working through the loop.

How could you change this flow chart to just print the numbers 1-5, or the numbers 5-10? What could we do/change or add to print the numbers 2,4,6,8,10 or the 5 times tables up to 50.

Examples

Example 3

Which of the following flowcharts contain a loop?

A
This image shows a flow chart. Ask your teacher for more information.
B
This image shows a flow chart. Ask your teacher for more information.
C
This image shows a flow chart. Ask your teacher for more information.
D
This image shows a flow chart. Ask your teacher for more information.
Worked Solution
Create a strategy

Choose the option with an action that goes back to a prior step.

Apply the idea

Options A and B are linear flow charts with no decisions to be made, so they do not have a loop.

Option D has a decision step but there is no movement backwards to repeat steps.

Option C has a loop starting at the diamond where it checks if number is bigger than 10. If it is not, it follows a loop and increases the value of number and then checks again.

The answer is option C.

Idea summary

SET is used to make a letter or word equal to a particular value.

PRINT is used to write an output either on the computer screen or on paper.

Loops in algorithms and flow charts mean that we repeat some action until a condition is satisfied and then we stop. They actually look like a loop in a flow chart.

What is Mathspace

About Mathspace