2.1 Algorithms End of Unit Quiz Lesson Element
2.1 Algorithms End of Unit Quiz Lesson Element
2.1 Algorithms End of Unit Quiz Lesson Element
1 Algorithms
1.
a. How is decomposition used when thinking computationally?
2.
ai. The array people contains the values:
What is the reason why this array could not be searched using a binary search?
aii. Once the issue identified in part (i) has been resolved, describe the steps that
would be taken to search the array for the value “Fletcher” using a binary search.
array people[5]
people = [“Imogen”, “Fletcher”, “Kirstie”, “Zoe”, “Gavin”]
found = False
x = 0
searchfor = input(“enter a name to search for : “)
while found = False ………… x <5
………………
c. A user has a database of 100,000 people and needs to search through to find one
particular person.
Compare the efficiency of both searching algorithms covered in parts (a) and (b)
for a data set of this size.
3.
ai. A programmer has a list of numbers in an array called scores, as shown below:
When setting up a bubble sort algorithm for these numbers, the programmer uses a
variable called swaps which can either be True or False.
aii. How would the programmer use this variable when implementing the bubble sort?
b. One section of the bubble sort algorithm used by the programmer is shown below:
What is the error that is contained in the code above? Give a corrected version.
c. How would an insertion sort algorithm arrange the numbers in the scores array
into order?
4. A school divides students into house groups based on the month that they were born in.
Students born in January, February, March or April are put into Needwood house. Students
born in May, June, July or August are put into Marchington House. All other students are
put into Trent house.
Ask the user to enter a number (1 to 12) relating to their birth month
Decide which house they are in and print this out.
Keep a running total of how many students are in each house.
Repeat the above for 20 students.
When 20 students have entered their details, print out how many students are in
each house.
5.
num = 7
7. A car dealer uses the following algorithm to determine the price to charge for cars.
ai. p = 1000, i = 2, a = 12
aiii. p = 8000, i = 0, a = 5
2.
ai. The array people contains the values:
What is the reason why this array could not be searched using a binary search?
aii. Once the issue identified in part (i) has been resolved, describe the steps that
would be taken to search the array for the value “Fletcher” using a binary search.
array people[5]
people = [“Imogen”, “Fletcher”, “Kirstie”, “Zoe”, “Gavin”]
found = False
x = 0
searchfor = input(“enter a name to search for : “)
while found = False AND x <5
Endwhile
Linear (search).
c. A user has a database of 100,000 people and needs to search through to find one
particular person.
Compare the efficiency of both searching algorithms covered in parts (a) and (b)
for a data set of this size.
3.
ai. A programmer has a list of numbers in an array called scores, as shown below:
17 9 4 -12 3 39
When setting up a bubble sort algorithm for these numbers, the programmer uses a
variable called swaps which can either be True or False.
aii. How would the programmer use this variable when implementing the bubble sort?
b. One section of the bubble sort algorithm used by the programmer is shown below:
What is the error that is contained in the code above? Give a corrected version.
Error
numbers are not swapped correctly / scores[x] will be overwritten
Correction (eg..)
temp = scores[x]
scores[x] = scores[x+1]
scores[x+1] = temp
c. How would an insertion sort algorithm arrange the numbers in the scores array
into order?
Merge sort.
4. A school divides students into house groups based on the month that they were born in.
Students born in January, February, March or April are put into Needwood house. Students
born in May, June, July or August are put into Marchington House. All other students are
put into Trent house.
Ask the user to enter a number (1 to 12) relating to their birth month
Decide which house they are in and print this out.
Keep a running total of how many students are in each house.
Repeat the above for 20 students.
When 20 students have entered their details, print out how many students are in
each house.
Example:
N = 0
M = 0
T = 0
FOR x = 1 to 20
INPUT birthnum
IF birthnum = 1 or birthnum = 2 or birthnum = 3 or birthnum = 4
THEN
print “Needwood house”
N = N + 1
ELIF birthnum = 5 or birthnum = 6 or birthnum = 7 or birthnum = 8
THEN
print “Marchington house”
M = M +1
ELIF birthnum = 9 or birthnum = 10 or birthnum = 11 or birthnum =
12 THEN
print “Trent house”
T = T + 1
ENDIF
print N, M, T
5.
num = 7
6. Complete the following table to describe the use of each of the following flow chart
symbols.
Input / output
Used to get information from /give information to the user
Suitable example (eg print “hello”)
Decision
Used to make yes/no decisions/choices
Suitable example (eg IF x > 10)
7. A car dealer uses the following algorithm to determine the price to charge for cars.
ai. p = 1000, i = 2, a = 12
1200
aii. p = 5000, i = 3, a = 10
aiii. p = 8000, i = 0, a = 5
16000
S=s*2
This formative assessment resource has been produced as part of our free GCSE teaching and learning support package. All the
GCSE teaching and learning resources, including delivery guides, topic exploration packs, lesson elements and more are available on
the qualification webpages.
If you are looking for examination practice materials, you can find Sample Assessment Materials (SAMs) on the qualification webpage:
Computer Science (9-1)
We’d like to know your view on the resources we produce. By clicking on ‘Like’ or ‘Dislike’ you can help us to ensure that our resources
work for you. When the email template pops up please add additional comments if you wish and then just click ‘Send’. Thank you.
Whether you already offer OCR qualifications, are new to OCR, or are considering switching from your current provider/awarding
organisation, you can request more information by completing the Expression of Interest form which can be found here:
www.ocr.org.uk/expression-of-interest
Looking for a resource? There is now a quick and easy search tool to help find free resources for your qualification:
www.ocr.org.uk/i-want-to/find-resources/