Stage 1 · Lesson 5 of 6
Amortised cost
Some operations are cheap most of the time and expensive once in a while. is their average cost over a long run of them. The classic case is adding to the end of a , a list that grows as you add to it.
Most just write into one free slot. When the array is full, it makes a new one twice the size and copies everything across. Because the size doubles each time, all that copying over n appends adds up to less than 2n.
So each append is O(1) amortised, even though a single one can cost O(n). Learn this now. It is why list append, insert and several later structures are called .
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Algorithm Complexity and Big-O
Design Gurus · Beginner · Subscription
Short course on exactly this stage, including the amortised and space cases people miss
- CourseFreeMIT 6.006 Introduction to Algorithms
MIT OpenCourseWare · Intermediate
Free: lecture 1 and recitation 1 on asymptotic notation and the model of computation
Keep handy
Also worth your time
Time and space complexity worked through five common algorithms