Six original Cambridge-style questions on comparing algorithms and Big O notation.
Explain what is meant by Big O notation and why it is used to compare algorithms.
State the time complexity of each algorithm in Big O notation: (a) binary search (b) bubble sort (c) linear search (d) popping an item from a stack.
An O(n) algorithm and an O(n2) algorithm each take 0.4 seconds to process 500 records. Estimate how long each takes for 2500 records. Show your working.
State how many times Total ← Total + i * j is executed when n = 8, and give the time complexity:
FOR i ← 1 TO n
FOR j ← 1 TO 4
Total ← Total + i * j
NEXT j
NEXT iA program stores 100 000 product codes. Compare keeping them in an unsorted array and searching with a linear search, with keeping them in a sorted array and searching with a binary search. Refer to time and space complexity.
A recursive function calls itself n times before reaching its base case, and each call does a fixed amount of work. State its time complexity and its space complexity, and explain the space complexity.
Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.