CleverSphere

Running times and big O notation

Big O notation describes how running time grows with the input. You should be able to place the main classes.

Rules

  • O(log n): halving
  • O(n log n): good sorting
  • O(n²): nested loops

Your turn

Three problems on this topic. Separate lists with commas.

  1. 1 · Running times
  2. 2
  3. 3

What is the running time?

Two nested loops over n

Running time

Worked example

What is the running time?

Insertion into an AVL tree

Worked solution

  1. 1Insertion into an AVL tree: O(log n)

Typical mistake: Quicksort is O(n log n) on average, but O(n²) in the worst case.

Common questions

What does worst case mean?

The input on which the algorithm takes longest.

Related

More topics