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

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 … Read more

Asymptotic Notation – does n (log n) (log n) simplify?

Here’s a proof by contradiction: Let’s say that a function f(n) = n(log n)(log n). Assume that we think it’s also Θ(n log n), theta(n log n), so in other words there is an a for which f(n) <= a * n log n holds for large n. Now consider f(2^(a+1)): f(2^(a+1)) = 2^(a+1) * log(2^(a+1)) * log(2^(a+1)) = 2^(a+1) * log(2^(a+1)) * (a+1), … Read more

Bellman-Ford vs Dijkstra: Under what circumstances is Bellman-Ford better?

Bellman-Ford algorithm is a single-source shortest path algorithm, so when you have negative edge weight then it can detect negative cycles in a graph. The only difference between the two is that Bellman-Ford is also capable of handling negative weights whereas Dijkstra Algorithm can only handle positives. From wiki However, Dijkstra’s algorithm greedily selects the … Read more