Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

What is an

algorithm?
Algorithm (noun):
In programming, algorithms are a set of step-by-step
instructions that tell a computer precisely what steps to take
to solve a problem or reach a goal. They are very much like a
recipe.
An algorithm has a well defined
sequence of steps, it gives you an
output, and it will eventually
terminate.
1 2 3 4 5 6

1 2 3 4 5 6
An algorithm is to solve a specific
problem or a class of problems.
algorithm

Pseudo-codes flowcharts
Pseudo-codes
It is intended for human reading rather than machine
reading.

It is an algorithm in English statements written in


outline form to conceptualise it before coding in a
programming language
For example, an algorithm written in pseudo-code for changing
a light bulb could be:
1. Retrieve spare bulb.
2. Turn off switch powering current bulb.
3. Unscrew current bulb.
4. Screw in spare bulb.
5. Turn on switch powering new bulb.
6. If spare bulb does not turn on, repeat steps 1 through 5.

BUT there’s something wrong here…..Can any you find it out?


For example, an algorithm written in pseudo-code for changing
a light bulb could be:
1. Retrieve spare bulb.
2. Turn off switch powering current bulb.
3. Unscrew current bulb.
4. Screw in spare bulb. Oops! We did not check if the bulb was too hot to touch
5. Turn on switch powering new bulb.
6. If spare bulb does not turn on, repeat steps 1 through 5.
Is the replacement bulb the correct type?

what to do with the bulb that we just replaced?


When you begin to build your own algorithms, you need to not
only make sure the algorithm works but that you’ve thought of
how to handle situations that tend to make or cause errors.

You should also be looking to make your algorithms as efficient as


possible – meaning you use as few lines of code as possible.
What are some other examples
of algorithm in your daily lives?
Use Mentimeter to type in your response
Algorithm example
Imagine that you are in the kitchen with your new pet robot. Your robot has a simple computer
brain – it needs to be told exactly how to make a peanut butter sandwich for you. This process
must be broken down into simple tasks for the robot to perform.

the robot can’t dip the knife into the jar of peanut butter as the lid is still on

This algorithm (another name for a set of instructions) was not detailed enough. Let’s try again!
Algorithm example
Imagine that you are in the kitchen with your new pet robot. Your robot has a simple computer
brain – it needs to be told exactly how to make a peanut butter sandwich for you. This process
must be broken down into simple tasks for the robot to perform.

It runs into trouble in the final step as the bread is still in its packet and cannot spread it.
Let’s try again!
Algorithm example
This final algorithm looks detailed enough to allow the robot to make a peanut butter sandwich and
give it to its owner.
We are going to do a:
Let’s make
our first Human
algorithm! Robot
Treasure
Hunt
• Discover how to write and
follow algorithms.

Welcome • Work in teams to guide a


"human robot" to treasure.
Explorers! • Enhance your problem-
solving and coding skills.
• In groups, write an algorithm
to find hidden treasure.
• Focus on precision in
What we are •
directions and distances.
Get ready to think like a
doing? programmer!
• Write step-by-step
Develop your •
instructions for your robot.
Example: "Walk forward 5
algorithm steps, turn right, then walk 3
steps and turn left.”
using • Accuracy is crucial—every
step and turn counts!
pseudo-code
• One team member will follow
the algorithm exactly as given
Robot in • Others will observe and note
any inaccuracies.
Action: Test • This is a test of your algorithm's
clarity and precision.
the algorithm
• If the algorithm doesn't work
correctly, debug by identifying
Evaluate and and fixing errors.
• Refine the algorithm to
Improve: improve accuracy and
efficiency.
Refine and • Discuss what went well and
what didn’t.
Debug • Prepare for a second trial with
your updated instructions.
• implement the revised
algorithm.
• Observe changes and further
Second refine if needed.
• Aim for your robot to
Time's the successfully find the treasure.

Charm
We are going to :
Now it’s
time to
share your • Share your algorithm and
experiences

adventures!
• Discuss common
challenges and how
they were overcome

You might also like