Engineering Questions with Answers - Multiple Choice Questions

Home » MCQs » Chemical Engineering » Recursive Insertion Sort MCQ’s

# Recursive Insertion Sort MCQ’s

Which of the following is an advantage of recursive insertion sort over its iterative version?

a) it has better time complexity

b) it has better space complexity

c) it is easy to implement

d) it has no significant advantage

**
View Answer**

Answer: d

Explanation: Recursive insertion sort has no significant advantage over iterative insertion sort. It is just a different way to implement the same

Insertion sort is an online sorting algorithm.

a) true

b) false

**
View Answer**

Answer: a

Explanation: Insertion sort does not require the entire input data in the beginning itself in order to sort the array. It rather creates a partial solution in every step, so future elements are not required to be considered. Hence it is an online sorting algorithm.

What will be the recurrence relation of the code of recursive insertion sort?

a) T(n) = 2T(n/2) + n

b) T(n) = 2T(n/2) + c

c) T(n) = T(n-1) + n

d) T(n) = T(n-1) + c

**
View Answer**

Answer: c

Explanation: The recurrence relation of the code of recursive insertion sort is T(n) = T(n-1) + n. It can be solved by the method of substitution and is found to be equal to n^{2}.

Which of the following sorting algorithm is stable?

a) Selection sort

b) Quick sort

c) Insertion sort

d) Heap sort

**
View Answer**

Answer: c

Explanation: Out of the given options insertion sort is the only algorithm which is stable. It is because the elements with identical values appear in the same order in the output array as they were in the input array.

Which of the following is a variant of insertion sort?

a) selection sort

b) shell sort

c) odd-even sort

d) stupid sort

**
View Answer**

Answer: b

Explanation: Shell sort is a variation of insertion sort. It has a better running time in practical applications.

Recursive insertion sort is a comparison based sort.

a) True

b) False

**
View Answer**

Answer: a

Explanation: In insertion sort, we need to compare elements in order to find the minimum element in each iteration. So we can say that it uses comparisons in order to sort the array. Thus it qualifies as a comparison based sort.

What is the average case time complexity of recursive insertion sort?

a) O(n)

b) O(n log n)

c) O(n^{2})

d) O(log n)

**
View Answer**

Answer: c

Explanation: The overall recurrence relation of recursive insertion sort is given by T(n) = T(n-1) + n. It is found to be equal to O(n^{2}).

What is the best case time complexity of recursive insertion sort?

a) O(n)

b) O(n log n)

c) O(n^{2})

d) O(log n)

**
View Answer**

Answer: a

Explanation: The best case time complexity of recursive insertion sort is O(n). It occurs in the case when the input is already/almost sorted

What is the worst case time complexity of recursive insertion sort?

a) O(n)

b) O(n log n)

c) O(n^{2})

d) O(log n)

**
View Answer**

Answer: c

Explanation: The overall recurrence relation of recursive insertion sort is given by T(n) = T(n-1) + n. It is found to be equal to O(n^{2}).

How many swaps will be required in the worst case to sort an array having n elements using binary insertion sort?

a) n

b) 1

c) n * log n

d) log n

**
View Answer**

Answer: d

Explanation: In a normal insertion sort at most n comparisons are required to sort the array. But if we also implement the concept of a binary sort in insertion sort then we can sort by having log n comparisons only.

What will be the base case for the code of recursive insertion sort ?

a)

if(n < 1) return;

b)

if(n == 0) return;

c)

if(n <= 1) return;

d)

If(n == 2) return;

**
View Answer**

Answer: c

Explanation: The most appropriate condition for the base case of recursive insertion sort is when n is less than or equal 1 then return. It is because we know that an array with only 1 element is always sorted.

What is the auxiliary space complexity of recursive insertion sort?

a) O(n)

b) O(1)

c) O(n log n)

d) O(n^{2})

**
View Answer**

Answer: b

Explanation: The auxiliary space required by recursive insertion sort is O(1). So it qualifies as an in place sorting algorithm.

Which of the following is an adaptive sorting algorithm?

a) recursive insertion sort

b) merge sort

c) heap sort

d) selection sort

**
View Answer**

Answer: a

Explanation: Insertion sort is an adaptive algorithm. It is because the time complexity of the algorithm improves when the input array is almost sorted.

Which of the following sorting algorithm is in place?

a) recursive insertion sort

b) merge sort

c) radix sort

d) counting sort

**
View Answer**

Answer: a

Explanation: Out of the given options recursive insertion sort is the only algorithm which is in place. It is because the auxiliary space required by recursive bubble sort is O(1).

Choose the correct function for recursive insertion sort?

a)

void RecInsertionSort(int arr[], int n) { if (n <= 1) return; RecInsertionSort( arr, n-1 ); int key = arr[n-1]; int j = n-2; while (j >= 0 && arr[j] > key) { arr[j+1] = arr[j]; j--; } arr[j+1] = key; }

b)

void RecInsertionSort(int arr[], int n) { if (n < 1) return; RecInsertionSort( arr, n-1 ); int key = arr[n-1]; int j = n-2; while (j >= 0 || arr[j] > key) { arr[j+1] = arr[j]; j--; } arr[j] = key; }

c)

void RecInsertionSort(int arr[], int n) { if (n <1) return; RecInsertionSort( arr, n-1 ); int key = arr[n-1]; int j = n-2; while (j >= 0 && arr[j] > key) { arr[j+1] = arr[j]; j--; } arr[j] = key; }

d)

void RecInsertionSort(int arr[], int n) { if (n <= 1) return; RecInsertionSort( arr, n-1 ); int key = arr[n-1]; int j = n-1; while (j >= 0 || arr[j] > key) { arr[j+1] = arr[j]; j--; } arr[j+1] = key; }

**
View Answer**

Answer: a

Explanation: The base case of recursive bubble sort should be when n equal or less than 1 then return. Also we need to insert the element being chosen as key at its correct position in the sorted array to its left. All this needs to be done in a recursive code.