You are on page 1of 20

Algorithms

BY: Mohamed Salb


What is algorithm?
What is algorithm?

• Algorithm: A series of simple, logical, step-by-step instructions that


must be followed in a strict sequence.
Using computational thinking to solve
problems
• Computational thinking: is a logical, strategic approach
to problem-solving.
• Computational thinking allows us to take a complex
problem, understand what the problem is and develop a
possible solutions.
• Computational thinking is made of four different stages:
 Decomposition
 Abstraction
 Pattern recognition
 Algorithm design
Pattern recognition

• Pattern recognition: the process of identifying


patterns in data.
• It is an important part of problem solving
because , if you can identify similarities between
two different problems, you might be apply to
apply the same or slightly modified solution to
both problems.
• This process helps programmers solve problems
more quickly and will require writing less code.
ACTIVITY (Making tea)
Using flow diagrams to solve computational
problems

• Flow diagrams: is a graphical


representation of the flow of something
through a system.
• Flow diagrams often used to illustrate the
sequence of instructions in an algorithm.
• There are slandered symbols for flow
diagrams.
Activity 1

Scenario: Coffee Machine


Let’s look at the algorithm used in a tea/coffee machine.
The machine should:
 Ask the user whether they want tea or coffee,
 Add the tea or the coffee to the cup,
 Ask the user whether they want milk,
 If so, add milk to the cup,
 Ask the user whether they want sugar,
 If so, add sugar to the cup,
 Pour the hot water into the cup.
Activity 1

Scenario: Coffee Machine


Let’s look at the algorithm used in a tea/coffee machine.
The machine should:
 Ask the user whether they want tea or coffee,
 Add the tea or the coffee to the cup,
 Ask the user whether they want milk,
 If so, add milk to the cup,
 Ask the user whether they want sugar,
 If so, add sugar to the cup,
 Pour the hot water into the cup.
Activity 2
Your Task: Pizza Vending Machine
Adapt the above algorithm to use it in a pizza robot. Here is what the
robot should do:
 Welcome the user,
 Ask what pizza base they need? (Thin, Thick)
 Ask if they want tomato sauce or BBQ sauce?
 Ask if they want cheese or not?
 Cook the pizza for 20 minutes,
 Serve the pizza
Extension:
 Ask if the user is vegetarian. If they are not, then ask if they want
chicken on their pizza.
 The cooking time of the pizza varies: It should be 15 minutes for a
thin base and 20 minutes for a thick base. Adapt your flowchart
accordingly.
Activity 2
Your Task: Pizza Vending Machine
Adapt the above algorithm to use it in a pizza robot. Here is what the
robot should do:
 Welcome the user,
 Ask what pizza base they need? (Thin, Thick)
 Ask if they want tomato sauce or BBQ sauce?
 Ask if they want cheese or not?
 Cook the pizza for 20 minutes,
 Serve the pizza
Extension:
 Ask if the user is vegetarian. If they are not, then ask if they want
chicken on their pizza.
 The cooking time of the pizza varies: It should be 15 minutes for a
thin base and 20 minutes for a thick base. Adapt your flowchart
accordingly.
Activity 2
Your Task: Pizza Vending Machine
Adapt the above algorithm to use it in a pizza robot. Here is what the
robot should do:
 Welcome the user,
 Ask what pizza base they need? (Thin, Thick)
 Ask if they want tomato sauce or BBQ sauce?
 Ask if they want cheese or not?
 Cook the pizza for 20 minutes,
 Serve the pizza
Extension:
 Ask if the user is vegetarian. If they are not, then ask if they want
chicken on their pizza.
 The cooking time of the pizza varies: It should be 15 minutes for a
thin base and 20 minutes for a thick base. Adapt your flowchart
accordingly.
ACTIVITY 3
https://www.101computing.net/flowchart-
prediction-tables/
ACTIVITY (MAZE ESCAPE)
What is generalisation?

• When a solution to a problem is applied to many similar types of


problems.

• It’s a key technique in programming, because it makes coding much


more efficient and improves productivity.
ACTIVITY (Meet the potato heads)
Page 98-99
Progress in Computing
HOMEWORK
MAZE ESCAPE ACTIVITY
ENTRY FEES TO AN AQUA PARK
Entry Fees Calculator using a Flowchart
For this challenge you will create a flowchart to explain the
process that a computer will have to follow to calculate the
entry fees to an aqua park for a small group of visitors or a
family.
Below is the price list of the aqua park:
 First you will design the flowchart for your algorithm. The
aim is your algorithm is to:
 Ask the user how many adult tickets are needed,
 Ask the user how many child tickets are needed,
 Calculate the total cost of this order,
 Decide if this order qualifies for a 5% discount and if so,
calculate the new total cost of the order,
 Output the total cost of the order.
Any Questions?

You might also like