DSA and problem solving

Stage 1 · Lesson 5 of 6

Amortised cost

Complexity and Big-O

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

  • CoursePaid
    Grokking Algorithm Complexity and Big-O

    Design Gurus · Beginner · Subscription

    Short course on exactly this stage, including the amortised and space cases people miss

  • CourseFree
    Algorithms, Part I

    Princeton University · Intermediate

    Free: the Analysis of Algorithms module measures real Java programs, then models their cost

Keep handy

Also worth your time

Mark this stage as not done?