Question bank › GCSE Computer Science › Fundamentals of algorithms

Efficiency of algorithms

Answer on paper first, then reveal the mark scheme one mark at a time.

1Grade 6–75 marks

Two algorithms both calculate the sum of the whole numbers from 1 to n.

Algorithm A

n ← STRING_TO_INT(USERINPUT)
total ← 0
FOR i ← 1 TO n
   total ← total + i
ENDFOR
OUTPUT total

Algorithm B

n ← STRING_TO_INT(USERINPUT)
total ← (n * (n + 1)) DIV 2
OUTPUT total

(a) State the output of both algorithms when the user enters 10. [1]

(b) Explain which algorithm is more efficient in terms of time. [2]

(c) A sorted list contains 1000 items. State the maximum number of items that would need to be checked against the search value to find an item (or show it is not there) using:

(i) a linear search [1]

(ii) a binary search. [1]

Still losing marks on this topic?

Book a free introductory session and we'll find exactly which step is costing you.

Book a free intro