MergeSort
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.
Insertion Sort  
Merge Sort  
Quick Sort  
Bubble Sort 
Discuss it
Question 1 Explanation:
See following for details.
http://www.geeksforgeeks.org/stabilityinsortingalgorithms/
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?
Heap Sort  
Selection Sort  
Insertion Sort  
Merge Sort 
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?
Heap sort  
Merge sort  
Quick sort  
Insertion sort 
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 35 is called as merging technique.
Question 4 
In a modified merge sort, the input array is splitted at a position onethird of the length(N) of the array. What is the worst case time complexity of this merge sort?
N(logN base 3)  
N(logN base 2/3)  
N(logN base 1/3)  
N(logN base 3/2) 
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.
Insertion Sort  
Heap Sort  
Merge Sort  
Selection Sort 
Discuss it
Question 5 Explanation:
The insertion sort will take [Tex]\theta[/Tex](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 mergesort algorithm. The worst case running time of this computation is
(A)
(B)
(C)
(D)
A  
B  
C  
D 
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 [Tex]O (n^2 log n) [/Tex].
Question 7 
Which of the following sorting algorithms has the lowest worstcase complexity?
Merge Sort  
Bubble Sort  
Quick Sort  
Selection Sort 
Discuss it
Question 7 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 8 
Which of the following is true about merge sort?
Merge Sort works better than quick sort if data is accessed from slow sequential memory.  
Merge Sort is stable sort by nature  
Merge sort outperforms heap sort in most of the practical situations.  
All of the above. 
Discuss it
Question 8 Explanation:
See Merge Sort and this.
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?
256  
512  
1024  
2048 
Discuss it
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?
Merge sort.
 
Bubble sort.  
Quick sort.  
Insertion sort.

Discuss it
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 10 questions to complete.
Coding practice for sorting.