Top MCQs on MergeSort Algorithm with Answers

Last Updated : 27 Sep, 2023

MergeSort is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for the two halves and then merges the two sorted halves. The merg() function is used for merging two halves. The merge(arr, l, m, r) is key process that assumes … More on Merge Sort
 

Quiz On Merge Sort

Quiz On Merge Sort


Question 1

Which of the following is not a stable sorting algorithm in its typical implementation.

Cross

Insertion Sort

Cross

Merge Sort

Tick

Quick Sort

Cross

Bubble Sort



Question 1-Explanation: 

Quick Sort is not a stable sorting algorithm in its typical implementation.

Question 2
You have to sort 1 GB of data with only 100 MB of available main memory. Which sorting technique will be most appropriate?
Cross
Heap sort
Tick
Merge sort
Cross
Quick sort
Cross
Insertion sort


Question 2-Explanation: 
The data can be sorted using external sorting which uses merging technique. This can be done as follows: 1. Divide the data into 10 groups each of size 100. 2. Sort each group and write them to disk. 3. Load 10 items from each group into main memory. 4. Output the smallest item from the main memory to disk. Load the next item from the group whose item was chosen. 5. Loop step #4 until all items are not outputted. The step 3-5 is called as merging technique.
Question 3

In a modified merge sort, the input array is splitted at a position one-third of the length(N) of the array. Which of the following is the tightest upper bound on time complexity of this modified Merge Sort.

Cross

N(logN base 3)

Cross

N(logN base 2/3)

Cross

N(logN base 1/3)

Tick

N(logN base 3/2)



Question 3-Explanation: 

The time complexity is given by: T(N) = T(N/3) + T(2N/3) + N Solving the above recurrence relation gives, T(N) = N(logN base 3/2)

Question 4

Which sorting algorithm will take least time when all elements of input array are identical? Consider typical implementations of sorting algorithms.

Tick

Insertion Sort

Cross

Heap Sort

Cross

Merge Sort

Cross

Selection Sort



Question 4-Explanation: 

The insertion sort will O(n) time when input array is already sorted.

Question 5

A list of n string, each of length n, is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation is

Cross

O (n*log(n))

Tick

O (n2 log n)

Cross

O (n2 + log(n))

Cross

O (n2)



Question 5-Explanation: 

The recurrence tree for merge sort will have height Log(n). And O(n^2) work will be done at each level of the recurrence tree (Each level involves n comparisons and comparison takes O(n) time in the worst case).

So time complexity of this Merge Sort will be O (n^2 log n)  .

Question 6

A list of n string, each of length n, is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation is

Cross

O (n*log(n))

Tick

O (n2 log n)

Cross

O (n2 + log(n))

Cross

O (n2)



Question 6-Explanation: 

The recurrence tree for merge sort will have height Log(n). And O(n^2) work will be done at each level of the recurrence tree (Each level involves n comparisons and comparison takes O(n) time in the worst case).

So time complexity of this Merge Sort will be O (n^2 log n)  .

Question 7

Which of the following sorting algorithms has the lowest worst-case complexity?

Tick

Merge Sort

Cross

Bubble Sort

Cross

Quick Sort

Cross

Selection Sort



Question 7-Explanation: 

Worst-case complexities for the above sorting algorithms are as follows:

  • Merge Sort: O(n*log(n))
  • Bubble Sort: O(n2)
  • Quick Sort: O(n2)
  • Selection Sort: O(n2)
Question 8

Which of the following is true about merge sort?

Cross

Merge Sort works better than quick sort if data is accessed from slow sequential memory.

Cross

Merge Sort is stable sort by nature

Cross

Merge sort outperforms heap sort in most of the practical situations.

Tick

All of the above.



Question 8-Explanation: 

Merge Sort satisfies all the three options given above.

Question 9
Assume that a mergesort algorithm in the worst case takes 30 seconds for an input of size 64. Which of the following most closely approximates the maximum input size of a problem that can be solved in 6 minutes?
Cross
256
Tick
512
Cross
1024
Cross
2048


Question 9-Explanation: 
Time complexity of merge sort is Θ(nLogn)

c*64Log64 is 30
c*64*6 is 30
c is 5/64

For time 6 minutes

5/64*nLogn = 6*60

nLogn = 72*64 = 512 * 9

n = 512. 
Question 10
What is the best sorting algorithm to use for the elements in array are more than 1 million in general?
Cross
Merge sort.
Cross
Bubble sort.
Tick
Quick sort.
Cross
Insertion sort.


Question 10-Explanation: 
Most practical implementations of Quick Sort use randomized version. The randomized version has expected time complexity of O(nLogn). The worst case is possible in randomized version also, but worst case doesn’t occur for a particular pattern (like sorted array) and randomized Quick Sort works well in practice. Quick Sort is also a cache friendly sorting algorithm as it has good locality of reference when used for arrays. Quick Sort is also tail recursive, therefore tail call optimizations is done.
There are 14 questions to complete.

 

Coding practice for sorting.

 


Share your thoughts in the comments

Similar Reads