Programming foundations

Stage 4 · Lesson 1 of 10

Big-O time complexity

Data structures and Big-O

describes time complexity: how the work your code does grows as its input gets bigger, ignoring fixed constants. One over n items is O(n). A loop inside a loop over the same items is O(n²).

Reading an item by its index is O(1), meaning the same cost at any size. Halving the problem at each step is O(log n). The differences are huge in practice.

At 100,000 items, an O(n²) solution does about 10 billion steps, while an O(n) one does 100,000. Learn this first in the stage, because every structure that follows is best understood by what its operations cost. Count the loops in your own code, and watch for hidden loops inside built-in calls, such as searching a list.

A question to check yourself, an AI practice session and 1 cheat sheet entry come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

Practise

Keep handy

  • Step through linked lists, hash tables and sorts with your own input

  • The Collections Framework section: ArrayList, LinkedList, HashMap, ArrayDeque

Also worth your time

Mark this stage as not done?