You are on page 1of 24

Algorithms and Flowcharts

Activity 1
What is this an example of and why are
they important?

It is of course a recipe

Important as it allows the


same meal to be made,
consistently, time and time
again.

It outlines a set of steps to


follow so that anyone can
create the same result.
Algorithms and Flowcharts
Learning
Objectives:
(a) understand algorithms
(written in pseudocode or
flow diagram), explain what
they do, and correct or

Hands up if you can


complete them
(b) produce algorithms in
pseudocode or flow
diagrams to solve problems.

explain the following:

What is an algorithm?
Algorithms and Flowcharts
Learning Algorithms
Objectives:
(a) understand algorithms
(written in pseudocode or
flow diagram), explain what • In general, an 'algorithm' is the
they do, and correct or
complete them name given to a set of steps
(b) produce algorithms in
pseudocode or flow needed to complete a task.
diagrams to solve problems.

• Think of an algorithm as a recipe.


For instance you could define an algorithm to
make a cup of tea. You start by filling the
kettle, then place a tea bag in the cup and so
on.

In computer terms, an algorithm describes the


set of steps needed to carry out a software task
or solve a problem
Algorithms and Flowcharts
Learning Algorithms
Objectives:
(a) understand algorithms
(written in pseudocode or Writing algorithms is all about problem
flow diagram), explain what
they do, and correct or
solving.
complete them
(b) produce algorithms in
pseudocode or flow After being given a problem to solve,
diagrams to solve problems.
programmers never begin programming
straight away, they will first do the
following:
- Think about the problem
- Break the problem down into smaller
chunks
- Think of the steps needed to solve each
chunk
- Write down the steps – which in turn
becomes the algorithm.
Algorithms and Flowcharts
Learning Writing Algorithms
Objectives:
(a) understand algorithms
(written in pseudocode or
flow diagram), explain what
they do, and correct or
complete them
Problem
(b) produce algorithms in
pseudocode or flow
diagrams to solve problems.

Algorithm
Algorithms
are
independent
of any
language
Algorithms and Flowcharts
Learning
Objectives:
(a) understand algorithms
(written in pseudocode or
flow diagram), explain what
they do, and correct or

Hands up if you can


complete them
(b) produce algorithms in
pseudocode or flow
diagrams to solve problems.

explain the following:

What is an algorithm?
Activity 2
• In your own words, write down the steps
needed to solve the following problem.

“Create a program that inputs two


numbers, adds them together and then
outputs the result onto the screen.”
Activity 2
• What did you get?
Did you have something like this?…
1. Ask user for a number
2. Store it in variable “number1”
3. Ask user for a second number
4. Store this in variable “number 2”
5. Add the two numbers together
6. Store the result in variable “answer”
7. Display the contents of “answer”.
Algorithms and Flowcharts
Learning Writing Algorithms
Objectives: Writing an algorithm in a Writing an algorithm in
(a) understand algorithms
(written in pseudocode or specific language: everyday language:
flow diagram), explain what
they do, and correct or
-Too time consuming
complete them
(b) produce algorithms in -Too time consuming -Inaccurate as it could be
pseudocode or flow -Pointless – could just code open to interpretation
diagrams to solve problems.
-Can’t be taken by a
programmer using a
different language
Algorithms are
-Too complex – need
independent of any knowledge of syntax (code
language specific to a language)

There are therefore methods used to write algorithms so that they are
succinct, accurate and easy to understand so that a programmer of any
language could understand the steps required to solve a task:

Flowcharts and Pseudocode


Algorithms and Flowcharts
Learning Writing Algorithms
Objectives: Problem: Calculate the Sales Tax (VAT) of an item
(a) understand algorithms
(written in pseudocode or and then using it to work out the final price
flow diagram), explain what
they do, and correct or
complete them 1. Flowchart
(b) produce algorithms in
pseudocode or flow
2. Pseudocode
diagrams to solve problems.

Examples of
each method of
algorithm
writing
Algorithms and Flowcharts
Learning Flowcharts
Objectives: Today we will focus on Flowcharts
(a) understand algorithms
(written in pseudocode or • Visual representation of a system
flow diagram), explain what
they do, and correct or • Small number of symbols used to represent
complete them individual steps
(b) produce algorithms in
pseudocode or flow • Arrows show the flow of control within the
diagrams to solve problems. algorithm (the order of instructions)
• Easier to trace a sequence of steps and locate
errors than in pseudocode.
Start Example:
A central heating system will try to
keep the temperature between 2
Is Yes
temp
Turn heating values (19 and 21)
on
< 19 - If the temperature falls below 19 It
No will turn the heating system on
Is Yes Turn heating
- If the temperature rises above 21
temp off it will switch the heating system
> 21
off.
No
Algorithms and Flowcharts
Learning
Objectives: Start and Stop Symbols
(a) understand algorithms
(written in pseudocode or
flow diagram), explain what All flow charts begin with a Start Symbol and at the
they do, and correct or end of the flow chart (or at various end points of
complete them
(b) produce algorithms in the chart) we place a Stop Symbol.
pseudocode or flow
diagrams to solve problems.
There are drawn as a rectangle with curved ends

Flowcharts Start
and their
symbols
Stop
Algorithms and Flowcharts
Learning
Objectives: Process Symbols
(a) understand algorithms
(written in pseudocode or
flow diagram), explain what Most of the time a flow chart will demonstrate the
they do, and correct or sequence of instructions to be carried out.
complete them
(b) produce algorithms in
pseudocode or flow Simple processes (like “Add 1 to x” or “append x to
diagrams to solve problems.
List”) are shown using a standard rectangle.

Flowcharts Add 1 to x
and their
symbols Append x
to “List”
Algorithms and Flowcharts
Learning
Objectives: Input / Output Symbols
(a) understand algorithms
(written in pseudocode or
flow diagram), explain what At times your program will most certainly ask the
they do, and correct or user for inputs and output values too.
complete them
(b) produce algorithms in
pseudocode or flow Inputs and Outputs (like “Name?” or “…display
diagrams to solve problems.
age”) are shown using a parallelogram.

Name?
Flowcharts
and their Store in variable
“Name”
symbols
Display
Name
Algorithms and Flowcharts
Learning
Objectives: Decision Symbols
(a) understand algorithms
(written in pseudocode or
flow diagram), explain what At times your program will be programmed to
they do, and correct or make a decision based on certain conditions.
complete them
(b) produce algorithms in
pseudocode or flow Decisions (like “IF X = 3” or “While Y > 3”) are shown
diagrams to solve problems.
using a diamond.

Flowcharts If X = 3
Yes
Display “X
equals 3”
and their
symbols No

Display “X
doesn’t
equal 3”
Algorithms and Flowcharts
Learning
Objectives:
(a) understand algorithms
(written in pseudocode or
flow diagram), explain what
they do, and correct or
complete them
(b) produce algorithms in
pseudocode or flow
diagrams to solve problems.

Flowcharts
and their
symbols
Algorithms and Flowcharts
Learning
Objectives:
(a) understand algorithms
(written in pseudocode or
flow diagram), explain what
they do, and correct or
complete them
(b) produce algorithms in
pseudocode or flow
diagrams to solve problems.

Flowcharts
and their
symbols
Algorithms and Flowcharts
Learning
Objectives:
4 things you need to be able
(a) understand algorithms
(written in pseudocode or
to do with algorithms for your
flow diagram), explain what
they do, and correct or exam
complete them
(b) produce algorithms in
pseudocode or flow • Understand them
diagrams to solve problems.
• Correct them if they have
errors,
• Complete them if they are
incomplete
• Produce them after being
given a problem to solve
Algorithms and Flowcharts
Learning
Objectives:
Tips on reading algorithms.
(a) understand algorithms
(written in pseudocode or
flow diagram), explain what
• Start from top and
they do, and correct or follow the arrows
complete them
(b) produce algorithms in
• Remember what the
pseudocode or flow symbols mean
diagrams to solve problems.
• Read each symbol
description
• Logically work out
what the algorithms
is doing.

Task: What is this algorithm doing?


Algorithms and Flowcharts
Learning
Objectives: Tips on correcting algorithms.
(a) understand algorithms
(written in pseudocode or Start
flow diagram), explain what
they do, and correct or
complete them
(b) produce algorithms in Is Yes Turn heating
pseudocode or flow
diagrams to solve problems.
Read the temp
on
> 19
flowchart and look
for decisions which No
Start
don’t make sense Is Yes Turn heating
temp off
< 21

X = 10
No

while Yes
X < 10
X=X+1 Or it might be a
No
loop which you
cannot get into or
End perhaps out of.
Algorithms and Flowcharts
Learning
Objectives:
Tips on completing
(a) understand algorithms
(written in pseudocode or algorithms. • Start from top and follow
flow diagram), explain what the arrows
they do, and correct or
complete them • Remember what the
(b) produce algorithms in symbols mean
pseudocode or flow
diagrams to solve problems. • Read each symbol
description
• Logically work out what the
algorithms is doing.
THEN,
• Use your knowledge
of the algorithm so far
• AND Use your
knowledge of the
follow chart symbols
• …and complete the
flowchart
Algorithms and Flowcharts
Learning
Objectives:
Tips on writing algorithms.
(a) understand algorithms
(written in pseudocode or
flow diagram), explain what
they do, and correct or
complete them
(b) produce algorithms in
pseudocode or flow
diagrams to solve problems.
Activity 3
• Make notes explaining what an
algorithm is, what a flowchart is and the
flowchart symbols for:
– start / stop
– input / output
– processes
– Decisions

You might also like