Edexcel International GCSE 9 1 Computer Science Student Book
Edexcel International GCSE 9 1 Computer Science Student Book
END IF
END IF
END IF
END IF
What would be the output of this algorithm for these test scores: 91, 56
and 78?
ITERATION
When writing programs, it is often necessary to repeat the same set of statements
several times. Instead of making multiple copies of the statements, you can
use iteration to repeat them. The algorithm for making a cup of coffee includes
an instruction to keep waiting until the water in the kettle boils.
CHECKPOINT
Strengthen
11: iff►
◄
CRITICAL THINKING,
DECISION MAKING S1 How are sequence, selection and iteration used in algorithms? Give
examples to justify your answer.
Challenge
IWi!�- PROBLEM SOLVING C1 Develop an algorithm using a flowchart that asks the user to enter
their height (in metres) and weight (in kilograms) and displays
their body mass index (BMI). The formula for calculating BMI is
weight/height 2 .
iim!f► PROBLEM SOLVING C2 Develop an algorithm expressed as a flowchart to control the heating
in a house. A thermostat monitors the temperature within the house.
During the week the temperature should be 20 °c between 06.00
and 08.30 in the morning and between 17.30 and 22.00 at night.
At weekends it should be 22°c between 08.00 and 23.00. If the
temperature in the house falls below 10 °C at any time the boiler is
switched on.
How confident do you feel about your answers to these questions? If you're
not sure you answered them well, try the following activities again.
SUMMARY
■ The constructs sequence, selection and iteration are the basic
building blocks of algorithms.
UNIT 1 PROBLEM SOLVING 3 SORTING AND SEARCHING ALGORITHMS 15
We are on all sorts of lists (for example, school and college, clubs and groups,
voting registers) and all these must be searched to find relevant information.
Sorting information is also important to facilitate efficient searches.
LEARNING OBJECTIVES
Understand how standard algorithms work (bubble sort, merge sort, linear
search, binary search)
Understand how the choice of algorithm is influenced by the data
structures and data values that need to be manipulated
Evaluate the fitness for purpose of algorithms in meeting specified
requirements efficiently, using logical reasoning and test data
Two of the most common tasks in computer programs are sorting data into a
particular order and searching for particular items of information.
There might be millions of items of stored data and searching for information
wouldn't be efficient if the data was not sorted. Imagine the confusion and
difficulty of having to find something in a dictionary that wasn't in alphabetical
order. Or planning a trip with train timetables that weren't sorted into time
order. Even small lists such as football league tables or the Top 20 music
charts are much more useful if they are sorted into order.
SORTING ALGORITHMS As sorting is such a widely used procedure, many algorithms have been created
to carry it out. As with all algorithms, some are more efficient than others.
SUBJECT VOCABULARY
BUBBLE SORT
When data is sorted, different items must be compared with each other and
ascending order this is arranging moved so that they are in either ascending order or descending order.
items from smallest to largest (e.g. 1, 2, 3)
descending order this is arranging The bubble sort algorithm starts at one end of the list and compares pairs of
items from largest to smallest (e.g. 3, 2, 1) data items. If they are in the wrong order, they are swapped. The comparison of
pairs continues to the end of the list, each complete traversal of the list being
traversal travel across or through called a 'pass'. This process is repeated until there have been no swaps during a
something. pass. This indicates that the items must all be in the correct order.