You are on page 1of 20

WORKBOOK ANSWERS

OCR AS/A Level Computer


Science Workbook 2
Elements of computational
thinking
Thinking abstractly
1 Removing detail that isn’t immediately important. (1)

Allows focus to be placed on the immediate data that is currently important. (1)

2 Any two of: (2)

 To make a map more user friendly.

 To make a protocol more reliable.

 To make a simulation more effective.

There may be many other suitable examples.

3 Abstraction is only a representation of reality. (1)

It does not represent the entirety of the reality itself as some data has been removed. (1)

4 It can hide the complexity of the program to allow focus on the immediate problem. (2)

It filters out unnecessary detail to create a representation of the current problem that needs
solving. (2)

5 Don’t need to refer to detail such as how many steps to take. (1)

Would filter out many buildings and landmarks, only referring to the major ones. (1)

Don’t need to refer to every road that is passed, only the ones where turns need to be made. (1)
Elements of computational thinking

Thinking ahead
6 It allows us to future-proof our program. (1)

It allows us to plan for every eventuality for our program. (1)

7 If we do not identify the correct inputs, then we may not get the correct outputs. (1)

If we do not plan for future inputs that may be needed, we may not be able to create the correct or
desired outputs. (1)

8 Libraries are pre-programmed sections of code that can be imported into our program. (1)

The creators of the programming language have thought about what common functions need to be
used and have created a library to do this, saving time. (1)

9 Caching is storing data and instructions in a temporary data store for easier access. (1)

It is anticipated which data and instructions are likely to be used most and these are added to the
cache. (1)

Thinking procedurally
10 To think about the sequence of the component parts of a solution. (1)

To make sure that the component parts are in the correct order to achieve the right output or
result. (1)

11 The problem needs to be broken down into individual parts/modules. (1)

12 If the sequence is incorrect then the output/result may be incorrect. (1)

There may be more than one way of achieving the output/result, so it can allow the most efficient
method to be identified. (1)

Thinking logically
13 One of: (1)

 Use a flowchart.

 Use pseudocode.

Thinking concurrently
14 Tasks can be completed in a faster time. (1)

Allows multitasking abilities. (1)

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 2


Elements of computational thinking

15 Any two of: (2)

 Programs have to be written with concurrency in mind.

 This can make programs much longer and more complex.

 Mistakes may be fed into later stages of the project.

Exam-style questions
16 a Decomposition: breaking down a problem into smaller parts. (1)

Abstraction: removing unnecessary information to reduce the complexity. (1)

b One of: (1)

 Problem recognition

 Devide and conquer

17 Any four of: (4)

 Think of all the surrounding data that may be encountered in a flight scenario.

 Assess which data is important for the user in the simulation.

 Assess which data is not useful for the user in the simulation.

 Remove the data that is not useful.

 Create a simulation that will include only the data that has been identified as important.

18 It allows the computer to complete more than one task at a time. (1)

It can fetch the next instruction whilst still processing the current instruction. (1)

It can divide larger problems into smaller parts and process them at the same time. (1)

It uses it to create the best performance ability possible for the computer. (1)

19 They allow us to use logic to decide what we would like for dinner. (1)

They do not consider any of our emotional feelings about what we might want for dinner. (1)

20 Any four of: (4)

 Larger tasks can be broken down into smaller ones.

 Analysis can take place to see which tasks can be completed alongside others.

 Assembly lines can be set to manufacture multiple parts of the product at the same time.

 All the parts can be assembled at the end to create the final product more efficiently.

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 3


Elements of computational thinking

 Some parts of the assembly line can be spraypainting parts whilst others are manufacturing
them (or another valid example).

21 Caching is storing data in a temporary area to make it easier/faster to access. (1)

Any three of: (3)

 The website may be viewed hundreds of times a week and caching can speed up the process
of accessing web pages.

 Once the content for a web page is requested once, it can be cached on a server, making it
quicker to access next time.

 The increased performance of the website, gained through caching, may attract more viewers.

 Caching can help the website deal with high volumes of traffic if they spike at certain points in
the day/week.

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 4


Problem solving and programming

Problem solving and


programming
Programming techniques
1 Iteration (1)

2 Conditional loop repeats until a condition is met/stops being met. (1)

Counting loop repeats a set number of times. (1)

3 An IF command is used (1) or a CASE/SWITCH command is used. (1)

A condition to be tested is created. (1)

4 A loop (1)

5 Base case. (1)

Steps working toward the base case (also known as general case). (1)

The recursive call. (1)

6 An infinite loop will be created. (1)

A stack overflow error will occur. (1)

7 A global variable is declared outside a subroutine and can be accessed at any time. (1)

A local variable is declared within a subroutine and can only be accessed within the subroutine. (1)

8 It means that it is less likely to be accidentally changed somewhere else in the program. (1)

9 If a variable needs to be used and updated by several different subroutines. (1)

10 Any two of: (2)

 It is easier to maintain or adapt.

 The programming of modules can be divided amongst different programmers.

 It allows for greater data security, as changes need only be made in one place rather than in
multiple places in the program.

 It can make it easier to identify where an error is occurring.

11 A function is a set of instructions designed to return a value, e.g. addition of values to gain a total.
(1)

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 5


Problem solving and programming

A procedure is set of instructions designed to perform a task that would not return a value, e.g. sort
data. (1)

12 A value that is passed into a subroutine. (1)

13 In passing by value, only a copy of the variable is passed into the subroutine. (1)

In passing by reference, the address of the variable is passed into the subroutine. (1)

14 Tools, such as pretty printing and auto-completion, can help the programmer understand that they
have the correct commands when writing the program. (1)

It can provide a testing environment and highlight where errors are present in the program. (1)

15 To initialise all the attributes in a class. (1)

16 a, b (6)

This is only a possible solution; student solutions may differ as different attributes and methods
can be used.

Animal
Height : Real
Weight : Real
Colour : String
Furry : Boolean
Age : Integer
getHeight()
getWeight()
getColour()
getFurry()
getAge()
setHeight()
setWeight()
setColour()
setFurry()
setAge()
Age_in_human_years()

Dog Cat
Breed : String Breed : String
Tail : Boolean Tail : Boolean
getBreed() getBreed()
getTail() getTail()
setBreed() setBreed()
setTail() setTail()
Age_in_human_years() Age_in_human_years()

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 6


Problem solving and programming

17 (2)

This is only a possible solution; student solutions may differ as different attributes and methods
can be used.

function getHeight()

return Height

endfunction

18 (2)

This is only a possible solution; student solutions may differ as different attributes and methods
can be used.

procedure setHeight(newHeight)

Height = newHeight

endprocedure

19 (3)

This is only a possible solution; student solutions may differ as different attributes and methods
can be used.

class Dog inherits Animal

private Breed

private Tail

public procedure new(newBreed, newTail)

Breed = newBreed

Tail = newTail

endprocedure

endclass

20 (1)

This is only a possible solution; student solutions may differ as different attributes and methods
can be used.

class Cat inherits Animal

21 (2)

This is only a possible solution; student solutions may differ as different attributes and methods
can be used.

myAnimal = new Animal(40.5, 15, "Brown", True, 6)

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 7


Problem solving and programming

Computational methods
22 An algorithm can be created to solve the problem. (1)

23 Any one of: (1)

 A problem that not enough data can be collected to solve.

 The underlying issues are too complex and are not understood.

 An algorithm cannot be created to solve the problem.

24 Breaking down a problem into smaller, more manageable parts. (1)

25 The inputs to the program. (1)

The outputs from the program. (1)

The processes that need to occur. (1)

The data that will need to be stored. (1)

26 It is easy to see which modules relate to each other, and are dependent on each other. (1)

27 It assumes the entire solution to the problem is known in advance, (1) which may not always be
possible, especially if event-driven programming is used. (1)

28 The OOP structure is an example of decomposition. (1)

The program is broken down into different modules, which are the classes within the program. (1)

29 Yes, it can be used. (1)

The Fibonacci sequence is found by a repetitive process (the addition of the previous two values to
make the current value). (1)

Recursion can be used to return each value, which is an example of divide and conquer. (1)

30 You may need to try one pattern of numbers to see if that works. (1)

But you may then hit a situation where it stops working, so you need to backtrack to the last point it
was working and try a different pattern. (1)

31 The recursive approach (1)

The depth-first approach (1)

32 Any two of: (2)

 You could backtrack to the point it was working and think what has been done since.

 You could physically roll the computer back to an earlier back-up.

 You could try one troubleshooting solution to see if that works.

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 8


Problem solving and programming

 If that doesn’t resolve the issue you can try another troubleshooting solution.

33 The company could analyse large sets of data about the current markets of their possible new
products. (1)

The data mining may reveal trends relating to the possible new products and help the company
decide which would be the most viable. (1)

34 It is a ‘rule of thumb’ thought that is developed through the experiences we have had in our lives.
(1)

35 Any two of: (2)

 We use them to make quick decisions.

 We use them to make decisions we regularly make.

 We use them to make decisions like those we have made before.

36 A program can be designed to use a heuristic approach to intelligently guess how to solve a
problem. (1)

37 It is a form of artificial intelligence as it involves computers imitating intelligent thought. (1)

38 The company can save money as they can repeatedly run the same tests or different tests in a
simulated situation. (1)

The company can save time as they wouldn’t need to wait for a physical model to be built each
time, or for a scenario to be reset. (1)

39 Any two of: (2)

 To load test a network.

 To penetration test a network.

 To refine the efficiency of a network.

40 It may not account for unknown or extenuating circumstances. (1)

It is limited to dealing with the problems and issues that we are able to think of. (1)

41 It would only be able to execute a single instruction at a time. (1)

42 It allows multiple instructions to be executed at the same time (in parallel). (1)

This can speed up the execution time for a program. (1)

43 It is not always possible to predict the next instruction needed if branching occurs in a program. (1)

44 Any one of: (1)

 A bar chart could quickly show which train routes are used the most.

 A plan of all the train routes colour co-ordinated for level of use.

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 9


Problem solving and programming

Exam-style questions
45 (4)

 Route module of parking meter. (1)

 Coin input and correct associated modules. (1)

 Green button and correct associated modules. (1)

 Display screen and correct associated modules. (1)

Parking meter

Coin input Green button Display screen

Coins Print ticket Give change Expiry time Cost

Calculate Calculate
Calculate cost
change expiry time

This is only a possible solution; student solutions may differ.

46 a To initialise all the values for the attributes in the class. (1)

b To return the value stored in the Salary attribute. (1)

c To update the value stored in the Overtime attribute. (1)

d (5)

 Correct class declaration header and close. (1)

 Variables declared as private. (1)

 Correct procedure header and close. (1)

 Correct parameters passed to procedure. (1)

 Parameter values assigned to correct attributes. (1)

class monthlyWage

private Name

private Salary

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 10


Problem solving and programming

private Overtime

public procedure new(newName, newSalary, newOvertime)

Name = newName

Salary = newSalary

Overtime = newOvertime

endprocedure

endclass

47 In a divide and conquer approach, problems are broken down into their smallest possible
components. (1)

Repeated actions are then performed on the components. (1)

This happens until a desired outcome is achieved. (1)

Two examples are recursion and binary search (other possible examples may be given). (2)

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 11


Algorithms

Algorithms
1 Any one of: (1)

 The efficiency of an algorithm.

 The worst-case scenario for the execution of an algorithm.

2 Logarithmic complexity OR log n (1)

3 Exponential complexity OR O(kn) (1)

Data structures
4 Polynomial complexity OR O(nk) (1)

5 Parameter value (1)

6 The stack is full so the value cannot be added. (1)

7 (4)

 Correct initialisation of variables. (1)

 Correct pointer values used throughout. (1)

 Correctly remove item from stack. (1)

 Identify if item is not in stack. (1)

This is only a possible solution; student solutions may differ.

function popFromStack()

indexFirst = 0

indexLast = 4

pointerTemp = endPointer

if pointerTemp <= indexFirst then

return false

else

valueToPop = stack[pointerTemp].data

endPointer = pointerTemp - 1

return true

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 12


Algorithms

endif

endfunction

8 A stack is a last in first out structure. (1)

A queue is a first in first out structure OR a queue can be circular. (1)

9 It has reached the end of the queue, so it needs to go back to the beginning. (1)

10 There is no free space in the queue for the value to be added. (1)

11 (4)

 Correct initialisation of variables. (1)

 Correct pointer values used throughout. (1)

 Correctly remove item from queue. (1)

 Identify if item is not in queue. (1)

This is only a possible solution; student solutions may differ.

function popFromQueue()

if StartPointer = EndPointer then

return false

else

valueToPop = queue[StartPointer].data

if StartPointer = 4 then

StartPointer = 0

else

StartPointer = StartPointer + 1

return true

endif

endif

endfunction

12 Any four of the comments in green: (4)

function itemToBeFound(dataItem) // function to see if a data item can be found in a list

currentPointer = startingPointer // sets the current pointer in the list to the start pointer

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 13


Algorithms

while currentPointer != nullPointer and list[currentPointer].data != dataItem // sets to loop while the
current pointer is not null and the current data item is not the one to be found

currentPointer = list[currentPointer].pointer // increments to the next pointer

endwhile

return currentPointer // returns the place in the list where the value is found

endfunction

13 The pointer from the previous node is disconnected from the value to be removed. (1)

The pointer from the value to be removed to the next node is disconnected and the deleted item is
added to the list of free space. (1)

The pointer is set to bypass the value to be removed and now points to the next value in the list
instead. (1)

14 The route node is the main node at the top of the hierarchy. (1)

15 A child node is a node that branches from a route node. (1)

16 (4)

 Correct placement of elephant, giraffe and lion. (1)

 Correct placement of antelope leopard and gorilla. (1)

 Correct placement of tiger and zebra. (1)

 Correct placement of penguin and wallaby. (1)

Monkey

Elephant Tiger

Antelope Giraffe Penguin Zebra

Leopard Lion Wallaby

Gorilla

17 Any one from: (1)

 A leaf node is a node that is at the end of a pathway.

 It has no other nodes branching from it.

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 14


Algorithms

18 To visit all nodes attached to a node connected to a starting node, before visiting a second node
attached to a starting node. (1)

19 To visit all nodes directly attached to a starting node first. (1)

Data searching and sorting


20 (5)

pointer = 0

indexMax = 9

value = input("Value to find")

while pointer < indexMax and list [pointer] != value then

pointer = pointer + 1

endwhile

if pointer >= indexMax then

output("Item not in list")

else

output("Item is at location " + pointer)

21 It must be ordered. (1)

22 (7)

lowerBound = 0

upperBound = lengthOfList – 1

found = false

searchValue = input("Value to find")

while found == false and upperBound != lowerBound

midpoint = round((lowerBound + upperBound)/2)

if list[midpoint] == searchValue then

found = true

elseif list[midpoint] < searchValue then

lowerBound = midpoint + 1

else

upperBound = midpoint – 1
OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 15


Algorithms

endif

endwhile

if found == false then

print("Not in list")

else

print("Item in position " + midpoint + " in list")

endif

23 If the data set is small. (1)

If the value is close to the beginning of the data set. (1)

24 If it doesn’t need to swap any values in a pass, it knows the data is in order. (1)

25 (3)

C F A B E D G

C A B E D F G
1st pass

A B C D E F G
2nd pass

A B C D E F G
Final pass

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 16


Algorithms

26 (4)

5 24 66 32 16 47 51 19

24 55 66 32 16 47 51 19

24 55 66 32 16 47 51 19

24 32 55 66 16 47 51 19

16 24 32 55 66 47 51 19

16 24 32 47 55 66 51 19

16 24 32 47 51 55 66 19

16 19 24 32 47 51 55 66

27 (5)

 Starts at the third value in the list. (1)

 Loop to analyse each value. (1)

 Correct comparison of values (1)

 Correct insertion of value. (1)

 Check made of end of list. (1)

This is only a possible solution; student solutions may differ.

numberOfValues = 8

for x = 2 to numberOfValues

valueToInsert = list[x]

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 17


Algorithms

index = x – 1

while list[index] > valueToInsert AND index >= 0

list[index + 1] = list[index]

endwhile

list[index] = valueToInsert

ENDFOR

28 (4)

55 24 66 32 16 47 51 19

24 55 32 66 16 47 19 51

24 32 55 66 16 19 47 51

16 19 24 32 47 51 55 66

29 a The merge sort (1) as it takes fewer passes/less processing of the data. (1)

b The insertion sort may be quicker if the data set was more sorted to begin with. (1)

30 (4)

 Taking first item, making it the pivot and having the correct values each sublist. (1)

 Making the first item in each sublist the pivot and having the correct values in the sublists. (1)

 Correct next stage of pivots and sublists. (1)

 Correct final sorted list. (1)

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 18


Algorithms

55 24 66 32 16 47 51 19

24 32 16 47 51 19 55 66

16 19 24 32 47 51 55 66

16 19 24 32 47 51 55 66

16 19 24 32 47 51 55 66

16 19 24 32 47 51 55 66

31 Divide and conquer. (1)

32 A–B–I–J (1)

33 Each estimation is an underestimate of the distance. (1)

Exam-style questions
34 (4)

Node Shortest distance from node 0 Previous node


0 0
1 3 0
2 1 0
3 4 0
4 2 2
5 4 4
6 8 5
7 4 4
Shortest path is 0–2–4–7.

35 a They are both bubble sorts. (1)

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 19


Algorithms

b It provides a form of data storage. (1)

It stores a Boolean value or a flag. (1)

c Parameter (1)

d Algorithm 1 would be more efficient (1) because it has:

 fewer lines of code for the computer to process (1)

 fewer processes/comparisons for the computer to handle (1)

 less data for the computer to store. (1)

36 The size of the array will be set (most likely to the size of the queue). (1)

The first piece of data added to the queue will be stored in the first element of the array. (1)

Further pieces of data added to the queue will be stored in the following elements of the array, in
the order added. (1)

An index will be stored as the front of the queue. (1)

An index will be stored as the end of the queue. (1)

OCR AS/A level Workbook: Computer Science 2

© Sarah Lawrey 2019 Hodder Education 20

You might also like