DevPrep

All topics › Algorithms & data structures

What is Big-O notation and why is it needed?

Junior PRO

The gist

Big-O describes how an algorithm's running time (or memory) grows with the input size n. Constants and lower-order terms are dropped: O(2n + 10) is O(n). By default it refers to the worst case; for Array.append and hash tables you should say "amortized" and "on average".

Classes in ascending order:

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store