Search code examples
algorithmcomplexity-theoryamortized-analysis

Connection between amortized complexity and worst case time complexity


I have a set of n consecutive operations which each one runs in O(1) amortized complexity. Can I say that the whole set runs in O(n) worst case time complexity? How do I prove it ?


Solution

  • You didn't give a code sample so I consider n consecutive operations as an algorithmic for-loop. So the task is to estimate worst case complexity of

    for(int i=1; i<n; i++)
    {
       f(x) // O(f(x)) = O(1)
    }
    

    In other words

    Sum(1,n) 1 = O(1) + O(1) + ... O(1) //n-times
    

    or

    O(1) + O(1) + ... O(1) = O(n)O(1) = O(n)