Understanding Algorithms -
Checkpoints
Strengthen
S1) Produce a written description of an algorithm for borrowing a book from the
library.
Go to the library. Ask the librarian if you can borrow a book. Choose the book you
want to borrow. Give that book to the librarian. Get the library card and the book.
Now, the book is borrowed.
S2) What is the function of the seven arithmetic operators?
1. The + sign is to add integers.
2. The - sign is to subtract integers.
3. The / sign is to divide integers.
4. the * sign is to multiply integers.
5. The % sign is to get the remainder from the integers which are divided.
6. The // sign is to get the quotient from the integers which are divided.
7. The ** sign is used to get the power of the base number as many times as
required.
S3) What is a variable? Why are they useful?
A variable is a subsect of an algorithm which is used to store a data type which is
liable to change. As they have the ability to change their stored value, they can be
used in programs to store values of data which can be changed.
S4) What is the difference between a variable and a constant?
A variable has the ability to change the value of its stored data whereas a constant
cannot change its stored data. It stays the same throughout the algorithm.
Challenge
C1) Produce a flowchart describing an algorithm for making a cheese sandwich.
Start
Go to the kitchen
Open the bread
packet
Take two slices of
bread
Open the fridge
Take one slice of
cheese out
Put the bread and
the cheese slices
together
End
C2) Write an algorithm expressed in pseudocode that receives three numbers from the
keyboard, then calculates and displays the average.
SEND ‘Please enter the first number’ TO DISPLAY
RECEIVE first_Number FROM KEYBOARD
SEND ‘Please enter the second number’ TO DISPLAY
RECEIVE second_Number FROM KEYBOARD
SEND ‘Please enter the third number’ TO DISPLAY
RECEIVE third_Number FROM KEYBOARD
SET total TO first_Number + second_Number + third_Number
SET average TO total / 3
SEND average TO DISPLAY
CREATING Algorithms -
Checkpoints
Strengthen
S1) How are sequence, selection and iteration used in algorithms? Give examples to
justify your answer.
Sequences are a step by step instruction that is followed until all the actions are
completed like a login protocol where the username is asked, checked then the
password is asked and checked before logging in. Selections follow a set of
instruction made for every possible scenario from the choice of the end-user. For
example, when browsing for e-books the user can choose the age and genre they
prefer to pick the appropriate book. Finally, iteration is a repetition of an
instruction until a task is completed like an age guesser which starts at 1 and goes
up until it guesses the age correctly.
Challenge
C1) Develop an algorithm using a flowchart that asks the user to enter their height (in
meters) and weight (in kilograms) and displays their body mass index (BMI). The
2
formula for calculating BMI is weight / height.
Start
Please enter your height in meters
and save as ‘height’
Please enter your weight in kilograms
and save as ‘weight’
height * height and
save as ‘squared’
weight / squared
and save as ‘BMI’
Display BMI to end user
End
C2) Develop an algorithm expresses as a flowchart to control the heating in a house. A
thermostat monitors the temperature within the house. during the week the house
should be 20 c between 6:00 and 8:30 in the morning and between 7:30 to 22:00 at
night. At weekends, it should be 22 c between 8:00 to 23:00. If the temperature in the
house falls below 10 c at any time the boiler is switched on.
Start
Is the
yes?
temp <= Switch the boiler on
10 c
no?
Is it
weekday
?
no? yes?
Is the Is the
no? no?
time = time =
6:00AM 8:00AM
yes?
yes?
Is the
no?
time =
Adjust the 7:30PM Adjust the
temperature to 20 c temperature
to 20 c
yes?
Adjust the
temperature to 20 c
no?
Is the
no?
time = Is the
no?
8:30AM time =
Is the 23:00AM
time =
yes?
22:00PM
yes?
yes?
End
SORTING & SEARCHING Algorithms -
Checkpoints
Strengthen
S1) What are the differences between the ‘bubble sort’ and ‘merge sort’ algorithms?
Bubble Sort Merge Sort
Doesn’t use a temporary
Uses a temporary variable
variable
Ideal for list with less than 1000
Ideal for list with bigger lists
items
Simple to code Complex codes
Comparatively slower Faster
S2) How does a binary search algorithm find the search item?
A binary search algorithm compares the values in the list and the search value until
it finds the needed item or reaches the end of the list without finding it.
Challenge
C1) When might a linear search be preferable to a binary search even if the binary
search algorithm is more efficient?
When the search value is the first in the list or the list on contains one item, the
search value.