WB Chapter 7 Algorithm Design and Problem Solving
WB Chapter 7 Algorithm Design and Problem Solving
7 problem solving
1 Identify and describe three stages of the program development lifecycle.
1
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
2
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
3
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
2 Abstraction, decomposition and structure diagrams are tools used during the program development
lifecycle. Identify the stage of the program development lifecycle where they are used and
describe what they are used for.
Abstraction
Stage: ...............................................................................................................................................................
Use: ....................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
Decomposition
Stage: ................................................................................................................................................................
Use: ....................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
Photocopying prohibited
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
5
Structure diagram
Stage: ................................................................................................................................................................
Use: ....................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
3 a Identify three of the different items, other than software, that make up a computer system.
1
.......................................................................................................................................................................
2
.......................................................................................................................................................................
3
.......................................................................................................................................................................
1
.......................................................................................................................................................................
2
.......................................................................................................................................................................
3
.......................................................................................................................................................................
4 Identify and describe the three methods you could use to design and construct a solution
to a problem.
1
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
2
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
3
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
Photocopying prohibited
6 Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
5 Use the following list of words and phrases to complete the paragraph below.
Each word or phrase can be used once, more than once or not at all.
» breakdown » description » hierarchical » top-down
» bottom-up » diagrammatic » level » structure diagram
» composition » flowchart » program » system
» decomposition » formal » pseudocode » sub-systems
Structure diagrams are used to show the .................................... design of a computer ....................................
in a .................................... form.
into .....................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
Photocopying prohibited
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
7
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
7 Describe the function of each of the following types of pseudocode statement and give an example
in pseudocode of the use of each one.
Assignment:
..................................................................................................................................................................................
..................................................................................................................................................................................
..................................................................................................................................................................................
..................................................................................................................................................................................
..................................................................................................................................................................................
Conditional:
..................................................................................................................................................................................
..................................................................................................................................................................................
..................................................................................................................................................................................
..................................................................................................................................................................................
..................................................................................................................................................................................
Photocopying prohibited
8 Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
Iterative:
..................................................................................................................................................................................
..................................................................................................................................................................................
..................................................................................................................................................................................
..................................................................................................................................................................................
..................................................................................................................................................................................
..................................................................................................................................................................................
For each one, describe the structure and write the pseudocode statements needed
to output the names of 20 students that have been stored in the array
Student[0:19]. Use the variable Counter for the iteration.
Loop 1: ..............................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
Loop 2: ..............................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
Photocopying prohibited
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
9
Loop 3: ..............................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
For each one, write the pseudocode statements needed to output a different welcome
message for each name input from 'Alice', 'Abid', 'Dinesh', 'Daisy' or 'Zak' or a rejection
message. Use the variable Name for the input.
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
Photocopying prohibited
10 Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
Photocopying prohibited
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
11
ii State, with reasons, which conditional statement is more appropriate to use in this case.
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
c There are two different ways of writing a flowchart to output the names of twenty students
that have been stored in the array Student[0:19]. The loop counter Counter is tested at
the start of the loop (pre-condition) or at the end of the loop (post-condition).
i Draw flowcharts for the pre-condition loop and the post-condition loop.
Pre-condition loop:
Post-condition loop:
Photocopying prohibited
12 Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
d When you have learnt how to write programs that include loops, write three programs to test
that your answers to part a work as intended.
Hint: for Python there will only be two programs.
Loop 1: ..............................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
Loop 2: ..............................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
Loop 3: ..............................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
Photocopying prohibited
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
13
9 a Write an algorithm in pseudocode to input ten numbers and output the total.
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
b Write an algorithm using a flowchart to input ten numbers and output the total.
Photocopying prohibited
14 Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
START
INPUT N
OUTPUT 'Please
enter your
guess:'
INPUT G
no
N ← N - 1
no N = 0?
yes
OUTPUT 'You
failed to guess
the word'
STOP
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
Photocopying prohibited
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
15
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
Photocopying prohibited
16 Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
11 Use the following list of words and phrases to complete the paragraph below.
Each word or phrase can be used once, more than once or not at all.
» algorithms » maximum
» average » mode
» bubble » minimum
» counter » search
» counting » sort
» linear » testing
» list » totalling
Standard methods of solution are used in the design of .............................................. . These include
adding in a new value every time an action occurs, for example, awarding a mark to each
student – this is called .............................................. . When divided by the number of times this
occurs, this gives the .............................................. . Keeping a record of the number of times an
In order to look for an item in a list a .............................................. is used. The method you need to
know for IGCSE Computer Science is to inspect each item in the .............................................. in turn to
To put a list in order a .............................................. is used. The method you need to know for IGCSE
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
Photocopying prohibited
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
17
b Write a bubble sort algorithm in pseudocode to sort a list of ten names, in an array called
Names[], in ascending order.
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
13 Validation and verification checks are used on values that are input into a computer program.
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
.......................................................................................................................................................................
1
.................................................................................................................................................................
2
.................................................................................................................................................................
1
.................................................................................................................................................................
2
.................................................................................................................................................................
Photocopying prohibited
18 Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
b i Boundary data is one type of test data. Identify and describe three other types of
test data.
1
.................................................................................................................................................................
.................................................................................................................................................................
.................................................................................................................................................................
.................................................................................................................................................................
2
.................................................................................................................................................................
.................................................................................................................................................................
.................................................................................................................................................................
.................................................................................................................................................................
3
.................................................................................................................................................................
.................................................................................................................................................................
.................................................................................................................................................................
.................................................................................................................................................................
ii Give the set of boundary data needed to check that a whole number is less than 100.
1
.................................................................................................................................................................
2
.................................................................................................................................................................
Photocopying prohibited
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
19
15 a Use the trace table and the test data 78, 34, 22, −4, 98, 16, 734, 88, 999 to record a
dry run of this algorithm written in pseudocode.
W ← 0
X ← 0
Y ← 100
Z ← 0
REPEAT
INPUT Mark
IF Mark <> 999
THEN
REPEAT
IF Mark < 0 OR Mark > 100
THEN
INPUT Mark
ENDIF
UNTIL Mark >= 0 AND Mark <= 100
IF Mark > X
THEN
X ← Mark
ENDIF
IF Mark < Y
THEN
Y ← Mark
ENDIF
Z ← Z + Mark
W ← W + 1
ENDIF
UNTIL Mark = 999
OUTPUT X, Y, Z
W X Y Z Mark OUTPUT
Photocopying prohibited
20 Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
Photocopying prohibited
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
21
d Use the guidance in Chapter 8 to rewrite this algorithm in pseudocode, ensuring that:
» there are meaningful prompts and outputs
» the algorithm could be read and understood by someone else.
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
22 Photocopying prohibited Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
e Devise another set of test data that includes normal, erroneous and extreme data and complete
a trace table to perform a dry run on your algorithm.
............................................................................................................................................................................
Trace table:
Photocopying prohibited
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
23
16 The following flowchart shows an algorithm that checks a temperature input is between 20 and
30 degrees. It contains several errors.
START
INPUT 'Please
enter the
temperature'
OUTPUT T
no
STOP
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
.............................................................................................................................................................................
Photocopying prohibited
24 Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
Photocopying prohibited
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
25