What is the big-O of the function (log n)^k

80,477

Solution 1

Any function whose runtime has the form (log n)k is O((log n)k). This expression isn't reducable to any other primitive function using simple transformations, and it's fairly common to see algorithms with runtimes like O(n (log n)2). Functions with this growth rate are called polylogarithmic.

By the way, typically (log n)k is written as logk n, so the above algorithm would have runtime O(n log2 n. In your case, the function log2 n + log n would be O(log2 n).

However, any function with runtime of the form log (nk) has runtime O(log n), assuming that k is a constant. This is because log (nk) = k log n using logarithm identities, and k log n is O(log n) because k is a constant. You should be careful not to blindly conclude that an algorithm that is O(log (nk)) is O(log n), though; if k is a parameter to the function or depends on n, the correct big-O computation would be O(k log n) in this case.

Depending on the context in which you're working, you sometimes see the notation Õ(f(n)) to mean O(f(n) logk n) for some constant k. This is sometimes called "soft-O" and is used in contexts in which the logarithmic terms are irrelevant. In that case, you could say that both functions are Õ(1), though this usage is not common in simple algorithmic analysis (in fact, outside of Wikipedia, I have seen this used precisely once).

Hope this helps!

Solution 2

It will still be (log(n))^2. A logarithm raised to a power is already in the lowest/simplest form.

Solution 3

(log n)^k is:

  • O((log n)^k)
  • O(n^k)
  • O(n)
  • O(n log n)
  • O(n^1/2)
  • O(n^0.00000002)

etc. Which one is meaningful for you depends on the constants and the context.

Solution 4

log(n) is O((log(n))^2) so the entire expression is O((log(n))^2)

Share:
80,477
Admin
Author by

Admin

Updated on August 16, 2022

Comments

  • Admin
    Admin over 1 year

    What is the big-O complexity of the function (log n)k for any k?

  • Foo Bah
    Foo Bah over 12 years
    one note on notation: you should be careful when writing log^k n because many randomized algorithms have complexities with terms like log(log(n)) or log(log(log(n))), and in some circles (e.g. in operations research), authors use log^k(n) to refer to repeated applications of logarithms.
  • templatetypedef
    templatetypedef over 12 years
    @Foo Bah- That's an excellent point. The notation log^* is also weird this way.
  • ypercubeᵀᴹ
    ypercubeᵀᴹ over 12 years
    Yeah, but it's only Θ((log n)^k)
  • Alexandre C.
    Alexandre C. over 12 years
    @ypercube: the OP didn't ask for big-theta.
  • ypercubeᵀᴹ
    ypercubeᵀᴹ over 12 years
    Yes, technically your answer is correct. I guess that's why you have +1
  • Neowizard
    Neowizard almost 10 years
    What do you think that log(n) is O((log(n))^2)?
  • Admin
    Admin almost 9 years
    @ypercube: it's also Θ((log n)^k + 1)