Search code examples
algorithmtime-complexitycomplexity-theorylogarithm

Calculating complexity of logarithm


As known the complexity to insert a node into AVL tree is log(c) when c is the number of nodes inside the tree. I'm looking to insert m nodes into the tree so the complexity is:

log(c)+log(c+1)+...+log(c+m)

Any ideas/suggestions on how I can solve this and get Big-O?


Solution

  • Assuming c is not a constant:

    log(c)+log(c+1)+...+log(c+m) = log(c * (c+1) * .... * (c+m))
                         = log((m+c)!/c!)
                         = log((m+c)!) - log(c!)
                         = O_theta((m+c)log(m+c)- clogc)
    

    But for the sake of the Big-O complexities, we usually quote the loose-bounds: O(NlogN) where N=m+c