Algorithms and complexity · A level · OCR H446 2.3.1, AQA 7517 4.4.4.1, Eduqas A500QS 1.3 · about 25 min
Time and space efficiency as functions of the size of the problem; linear, polynomial, exponential and logarithmic functions; permutations and n!.
[1 mark]Why are algorithms compared by counting operations as a function of n rather than by timing them?
[1 mark]Which of these is an exponential function of n?
[1 mark]What is log₂ 256?
[1 mark]In how many different orders can a robot visit 5 distinct checkpoints?
[1 mark]Checking a list for repeats by storing every item seen in a set, instead of comparing every pair, makes which of these true?
Tick every answer that is true.
[1 mark]What does this print?
n = 1
for k in range(1, 6):
n = n * k
print(n, 2 ** 5, 5 ** 2)Print a table of how four functions grow. For each n in 4, 8, 16, 32 and 64, print one line in exactly this form:
n=8 log2=3 square=64 exponential=256
where log2 is log₂ n (a whole number here, because every n is a power of 2), square is n² and exponential is 2ⁿ. Work out log2 by counting how many times n can be halved (with // 2) before it reaches 1, not with the math module.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
n = 8
print("n=" + str(n))Plan your program here, then type it in and press Run.