levo

Theory of Computation

Order of complexity and Big-O notation

  • 2 things to know
  • Paper 1

Overview

Recall questions on constant, logarithmic, linear, polynomial and exponential growth, and on deriving an algorithm's complexity from its code.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What does constant time mean, and give two examples?

Process

Derive the complexity of this algorithm. count ← 0 WHILE n > 1 n ← n DIV 2 count ← count + 1 ENDWHILE.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What does Big-O notation express?

    Model answer

    Big-O notation expresses how an algorithm’s requirements grow as the size of the problem grows — most often its running time, though the same notation describes the memory it needs. It names the shape of the growth rather than an exact number of operations, so it describes the algorithm itself independently of the machine it runs on.

  2. 2

    Name the five orders of growth you must be able to recognise, in increasing order of how badly they grow.

    Model answer

    Constant time O(1), logarithmic time O(log n), linear time O(n), polynomial time such as O(n²), and exponential time such as O(2ⁿ).

  3. 3

    What does constant time mean, and give two examples?

    Model answer

    Constant time, O(1), means the running time does not depend on the size of the problem at all — the same amount of work is done whether there are ten items or ten million. Reading the element at a given index of an array is O(1), because the address is calculated directly from the index. Pushing an item onto a stack held as an array with a top pointer is O(1), because it writes one item and adjusts one pointer regardless of how many items are already there.

  4. 4

    What does logarithmic time mean, and give an example with numbers?

    Model answer

    Logarithmic time, O(log n), means that each step disposes of a fixed fraction of what remains, so the work grows extremely slowly with problem size. Binary search on a list of 1000 items needs at most about 10 comparisons, because each comparison halves the range and 2¹⁰ = 1024; doubling the list to 2000 items adds just one more comparison. This holds only if the list is already sorted and any element can be reached directly by index.

  5. 5

    What does linear time mean, and give an example?

    Model answer

    Linear time, O(n), means the running time grows in direct proportion to the size of the problem: double the data and the algorithm takes about twice as long. Finding the largest value in an unsorted list of n items is O(n), because every item must be examined once and no fewer would do. Linear search is also O(n) in the worst case, examining all n items when the target is last or absent.

  6. 6

    What does polynomial time mean, and give an example?

    Model answer

    Polynomial time means the running time grows as a fixed power of the problem size, such as O(n²) or O(n³). Bubble sort is O(n²): it makes about n passes and each pass makes about n comparisons, so doubling the number of items multiplies the work by roughly four. Comparing every item in a list with every other item is likewise O(n²), and comparing every triple would be O(n³).

Other ways to work this

The same content, four other ways.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

A driver is .
softwarehardwarestorage

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

AThe integer 5 is 0101.
B0.75 is 1/2 + 1/4.
CThe fraction bits are 1100.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

Head means the first single element of a non-empty list.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Theory of Computation, on a schedule.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.