0% found this document useful (0 votes)
41 views25 pages

Algorithms - KS4

The document describes representing algorithms through different methods like written descriptions, flowcharts, and code. It discusses the difference between algorithms and computer programs. The document then provides examples of writing algorithms as written steps, flowcharts, and code. It also introduces common flowchart symbols and provides an example of a full flowchart for a coin toss game.

Uploaded by

pete555
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views25 pages

Algorithms - KS4

The document describes representing algorithms through different methods like written descriptions, flowcharts, and code. It discusses the difference between algorithms and computer programs. The document then provides examples of writing algorithms as written steps, flowcharts, and code. It also introduces common flowchart symbols and provides an example of a full flowchart for a coin toss game.

Uploaded by

pete555
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Lesson 2: Representing

algorithms
KS4 - Algorithms
Starter activity

Building Lego

Imagine giving these Lego instructions to


five different people.

Question:
Do you think that everyone's finished
product will look the same? Why?

Think, write, pair, share.

2
Objectives

Lesson 2: Representing algorithms


In this lesson, you will:
● Describe the difference between algorithms and computer programs

● Identify algorithms that are defined as written descriptions, flowcharts and code

● Analyse and create flowcharts using the flowchart symbols

3
Activity 1

Algorithms

An algorithm is a set of precise


instructions, expressed in some sort of
language (e.g. textual, visual).
Understanding the language is necessary
in order to execute the instructions.
Executing these instructions is meant to
solve a problem.

4
Activity 1

Algorithms and computer programs


The terms algorithms and computer programs can often overlap but are distinct from
one another.

What do you think the difference is between an algorithm and a computer program?

5
Activity 1

Algorithms and computer programs


An algorithm describes the logic of a solution.

A computer program is an implementation of this solution, written in a programming


language.

Programs written in a programming language are precise enough for a machine to


translate and then execute.

6
Activity 2

Representing algorithms
In computer science, algorithms can be represented in a number of ways, not only in a
programming language.

For instance, you can use flowcharts and written descriptions to help you to focus on
the logic of a solution without worrying about syntax errors.

This can massively speed up the development time of a program.

7
Activity 2

Flowcharts
Start

A flowchart can be used to visually


Input
represent an algorithm or program. year_born

Arrows are used to signify the flow of the Input


program. current_year

result = current_year - year_born

What does this algorithm do?


Output
result

End
8
Activity 2

Written descriptions
Start

A written description can also be used to


Input
specify the steps of an algorithm: year_born

1. Ask the user for the year they were Input


born. current_year
2. Ask the user for the year it currently is.
3. Subtract the current year by the year result = current_year - year_born
born.
4. Tell the user how old they will be this Output
year. result

End
9
Activity 2

Computer program
Start

Once the logic of an algorithm is planned


Input
out, you can use it to help with writing year_born
code in a programming language, such as
Python: Input
current_year

year_born = int(input())
current_year = int(input()) result = current_year - year_born

result = current_year - year_born


print(result) Output
result

End
10
Activity 3

Creating flowcharts

In the next activity, you are going to


develop a flowchart.

First though, you need to know what the


different flowchart symbols are and what
they represent.

11
Activity 3

Flowchart symbols

Start welcome
Terminators are used for the start and Subroutines are represented by a
end of subroutines or programs. rectangle with two lines either side.

Arrows are
used to show the direction and flow of the
program.

12
Activity 3

Flowchart symbols

Output “Hello
Input name
world!”

An input or output is represented by a


parallelogram. age <
16?
False
A decision has two
branches, True and
squared = num1 * num2
True False.
A
process is represented by a rectangle. It is
used for an instruction or command.

13
Activity 3

Written description for coin toss


The following slides go over a step-by-step breakdown of a flowchart for a coin toss
game. The instructions for the game can be written as:

1. Ask the user to guess either “Heads” or “Tails”.


2. Simulate a coin flip by randomly generating either “Heads” or “Tails”.
3. Compare the coin flip with the user’s choice.
4. If the coin flip is the same as the user’s choice, tell the user they won.
5. Otherwise, tell the user they lost.

14
Activity 3

Flowchart for coin toss


Start Begin the flowchart with a start
terminator.

15
Activity 3

Flowchart for coin toss


Start

Output Ask the user to guess either “Heads”


“Heads or Tails?” or “Tails” and store the response in a
variable called choice.
Input choice

16
Activity 3

Flowchart for coin toss


Start

Output
“Heads or Tails?”

Input choice

flip = Randomly pick Simulate a coin toss by randomly


“Heads” or “Tails” generating either “Heads” or “Tails”.
Store this in a variable called flip.

17
Activity 3

Flowchart for coin toss


Compare the coin flip with the user’s
Start
choice.
choice ==
Output flip? False
“Heads or Tails?”
True

Input choice

flip = Randomly pick


“Heads” or “Tails”

18
Activity 3

Flowchart for coin toss


Start
choice ==
Output flip? False
“Heads or Tails?”
True

Input choice Output


“You won!”
If the coin flip is the same as the
flip = Randomly pick
user’s choice, tell the user they won.
“Heads” or “Tails”

19
Activity 3

Flowchart for coin toss


Start
choice ==
Output flip? False
“Heads or Tails?”
True

Input choice Output Output


“You won!” “You lost!”

flip = Randomly pick


“Heads” or “Tails”
Otherwise, tell the user they lost.

20
Activity 3

Flowchart for coin toss


Start
choice ==
Output flip? False
“Heads or Tails?”
True

Input choice Output Output


“You won!” “You lost!”

flip = Randomly pick


“Heads” or “Tails”
End Finish the flowchart with an end
terminator.

21
Activity 3

Dice roll

Now it is your turn to create a flowchart


for a dice roll simulation.

Use the written description included in the


Activity 3 Worksheet to develop your
flowchart.

22
Plenary

Peer review your flowcharts

Sit with a partner and peer review your


flowcharts.
Check that the logic of the flowcharts will
result in the intended outcome.
Use the worksheet solution to help you
with this.

23
Homework

Homework: Odd or even?

Modify your dice roll flowchart so that it


checks whether each dice that was rolled
is odd or even.

If a dice is even the flowchart should


output “Even”, whilst if the dice is odd
the flowchart should output “Odd”.

Due: Next lesson

24
Summary

Next lesson

In this lesson, you… Next lesson, you will…

Described the difference between Use trace tables to walk through


algorithms and computer programs. algorithms in code.

Identified algorithms that are defined as


written descriptions, flowcharts and code.

Analysed and created flowcharts using the


flowchart symbols.

25

You might also like