Space Complexity:
The term Space Complexity is misused for Auxiliary Space at many places. Following are the correct definitions of Auxiliary Space and Space Complexi...

Share

What is the time complexity of following function fun()? Assume that log(x) returns log value in base 2.
void fun()
{
   int i, j;
 &...

Share

Consider the following algorithm for building a Heap of an input array A.
BUILD-HEAP(A)
heapsize := size(A);
for i := floor(heapsize/2) downto 1
...

Share

What is the time complexity of below code?
void fun(int n)
{
   int j = 1, i = 0;
   while (i < n)
   {
...

Share

What is the time complexity of below function?
void fun(int n, int k)
{
    for (int i=1; i<=n; i++)
    {
&#x...

Share

The classical Sieve of Eratosthenes algorithm takes O(N log (log N)) time to find all prime numbers less than N. In this article, a modified Sieve is discussed that w...

Share

Question : How much time Insertion sort takes to sort an array of size n in below form?
arr[] = 2, 1, 4, 3, 6, 5,….i, i-1, …..n, n-1
Answer : At first ...

Share

What is an inversion?
Given an array arr[], a pair arr[i] and arr[j] forms an inversion if arr[i] < arr[j] and i > j. For example, the array {1, 3, 2, 5} has on...

Share

The worst case time complexity of a typical implementation of QuickSort is O(n2). The worst case occurs when the picked pivot is always an extreme (smallest or larges...

Share

Consider the following algorithm for building a Heap of an input array A.
BUILD-HEAP(A)
heapsize := size(A);
for i := floor(heapsize/2) downto 1
...

Share