It is a well established fact that merge sort runs faster than insertion sort. Using asymptotic analysis we can prove that merge sort runs in O(nlogn) time and insertion sort takes O(n^2). It is obvious because merge sort uses a divide-and-conquer approach by recursively solving the problems where as insertion sort follows an incremental approach.… Read More »
For such cases, time complexity of the loop is O(log(log(n))).The following cases analyse different aspects of the problem. Case 1 : In this case, i takes values 2, 2k, (2k)k = 2k2, (2k2)k = 2k3, …, 2klogk(log(n)). The last term must be less than or equal to n, and we have 2klogk(log(n)) = 2log(n) =… Read More »
What is Pseudo-polynomial? An algorithm whose worst case time complexity depends on numeric value of input (not number of inputs) is called Pseudo-polynomial algorithm. For example, consider the problem of counting frequencies of all elements in an array of positive numbers. A pseudo-polynomial time solution for this is to first find the maximum value, then… Read More »
What is the time complexity of below code?
What is the time complexity of below function?
What is the time complexity of following function fun()?
Consider the following C function.
Amortized Analysis is used for algorithms where an occasional operation is very slow, but most of the other operations are faster.
What is tail recursion? A recursive function is tail recursive when recursive call is the last thing executed by the function.
In the previous post, we discussed analysis of loops. Many algorithms are recursive in nature.
We have discussed Asymptotic Analysis, Worst, Average and Best Cases and Asymptotic Notations in previous posts.