This Test will cover basic concepts of various sorting algorithms and time complexity of algorithms.

Q. What is recurrence for worst case of **QuickSort** and what is the time complexity in Worst case?

Q. Suppose we have a **median** of an unsorted array. Now consider a **QuickSort** implementation where we first find **median** using the above algorithm, then use **median** as **pivot**. What will be the worst case time complexity of this modified **QuickSort**

`O(n)`

time algorithm that finds Q. Given an unsorted array. The array has a property that every element in the array is at most

`k`

distance from its position in sorted array, where `k`

is a positive integer smaller than the size of array. Which sorting algorithm can be easily modified for sorting this array and what is the obtainable time complexity?Q. Which of the following is not true about comparison based sorting algorithms?

Q. What is time complexity of

`fun()`

?```
int fun(int n)
{
int count = 0;
for (int i = n; i > 0; i /= 2)
for (int j = 0; j < i; j++)
count += 1;
return count;
}
```

Q. What is time complexity of

`fun()`

?```
int fun(int n)
{
int count = 0;
for (int i = 0; i < n; i++)
for (int j = i; j > 0; j--)
count = count + 1;
return count;
}
```

Q. The recurrence relation capturing the optimal time of the **Tower of Hanoi** problem with

`n`

discs is __________?Q. Let

`W(n)`

and `A(n)`

denote respectively, the worst case and average case running time of an algorithm executed on an input of size `n`

. Which of the following is ALWAYS TRUE?
Q. Which of the following is not O(n^{2})?

Q. Which of the given options provides the increasing order of asymptotic complexity of functions f1, f2, f3 and f4?

f1(n) = 2^{n}f2(n) = n^{(3/2)}f3(n) = n*Logn f4(n) = n^{Logn}

Q. Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let **n = D1D2...Dm**, where D1, D2 etc are digits forming the integer number. The loop invariant condition at the end of the **ith** iteration is:

```
rev = 0;
while (n > 0)
{
rev = rev*10 + n%10;
n = n/10;
}
```

Q. What is the best time complexity of Bubble Sort?

Q. What is the worst case time complexity of **Insertion sort** where position of the data to be inserted is calculated using **Binary search**?

Q. The tightest lower bound on the number of comparisons, in the worst case, for comparison-based sorting is of the order of:

Q. In a modified **Merge sort**, the input array is splitted at a position one-third of the length(

`N`

) of the array. What is the worst case time complexity of this merge sort?
Tests for various other programming languages and subjects: