# MergeSort

• Last Updated : 30 Jul, 2021

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

 Question 1
Which of the following is not a stable sorting algorithm in its typical implementation.
 A Insertion Sort B Merge Sort C Quick Sort D Bubble Sort
Sorting    QuickSort    InsertionSort    MergeSort
Discuss it

Question 1 Explanation:
 Question 2
Consider a situation where swap operation is very costly. Which of the following sorting algorithms should be preferred so that the number of swap operations are minimized in general?
 A Heap Sort B Selection Sort C Insertion Sort D Merge Sort
Sorting    InsertionSort    SelectionSort    MergeSort
Discuss it

Question 2 Explanation:

Selection sort makes O(n) swaps which is minimum among all sorting algorithms mentioned above.

 Question 3
You have to sort 1 GB of data with only 100 MB of available main memory. Which sorting technique will be most appropriate?
 A Heap sort B Merge sort C Quick sort D Insertion sort
Sorting    QuickSort    MergeSort    HeapSort
Discuss it

Question 3 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 4
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.
 A N(logN base 3) B N(logN base 2/3) C N(logN base 1/3) D N(logN base 3/2)
Sorting    MergeSort    Analysis of Algorithms
Discuss it

Question 4 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 5
Which sorting algorithm will take least time when all elements of input array are identical? Consider typical implementations of sorting algorithms.
 A Insertion Sort B Heap Sort C Merge Sort D Selection Sort
Sorting    InsertionSort    MergeSort    SelectionSort
Discuss it

Question 5 Explanation:
The insertion sort will take (n) time when input array is already sorted.
 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
 A O (n log n) B O (n2 log n) C O (n2 + log n) D O (n2)
MergeSort    MergeSort    Analysis of Algorithms
Discuss it

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 a comparison takes O(n) time in worst case). So time complexity of this Merge Sort will be .
 Question 7
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
 A O (n log n) B O (n2 log n) C O (n2 + log n) D O (n2)
MergeSort    MergeSort    Analysis of Algorithms
Discuss it

Question 7 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 a comparison takes O(n) time in worst case). So time complexity of this Merge Sort will be .
 Question 8
Which of the following sorting algorithms has the lowest worst-case complexity?
 A Merge Sort B Bubble Sort C Quick Sort D Selection Sort
Sorting    SelectionSort    Analysis of Algorithms    MergeSort
Discuss it

Question 8 Explanation:
Worst case complexities for the above sorting algorithms are as follows: Merge Sort — nLogn Bubble Sort — n^2 Quick Sort — n^2 Selection Sort — n^2
 Question 9
Which of the following is true about merge sort?
 A Merge Sort works better than quick sort if data is accessed from slow sequential memory. B Merge Sort is stable sort by nature C Merge sort outperforms heap sort in most of the practical situations. D All of the above.
Sorting    QuickSort    MergeSort    HeapSort
Discuss it

Question 9 Explanation:
See Merge Sort and this.
 Question 10
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?
 A 256 B 512 C 1024 D 2048
GATE-CS-2015 (Set 3)    Sorting    MergeSort
Discuss it

Question 10 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. 
There are 14 questions to complete.

## Coding practice for sorting.

My Personal Notes arrow_drop_up