/* */ Click to Join Live Class with Shankar sir Call 9798158723

# Data Structure MCQ - Sorting

Q1.What is an in-place sorting algorithm?
1. It needs O(1) or O(logn) memory to create auxiliary locations
2. The input is already sorted and in-place
4. None of the mentioned

Explanations :Auxiliary memory is required for storing the data temporarily.
Q2.In the following scenarios, when will you use selection sort?
1. The input is already sorted
2. A large file has to be sorted
3. Large values need to be sorted with small keys
4. Small values need to be sorted with large keys

Explanations :Selection is based on keys, hence a file with large values and small keys can be efficiently sorted with selection sort.
Q3.Select the appropriate code that performs selection sort.
1. int min; for(int j=0; j< arr.length-1; j++) { min = j; for(int k=j+1; k<=
2. int min; for(int j=0; j< arr.length-1; j++) { min = j; for(int k=j+1; k
3. int min; for(int j=0; j< arr.length-1; j++) { min = j; for(int k=j+1; k<=<
4. int min; for(int j=0; j< arr.length-1; j++) { min = j; for(int k=j+1; k<=<

Explanations :Starting with the first element as 'min' element, selection sort loops through the list to select the least element which is then swapped with the 'min' element.
Q4.What is the advantage of selection sort over other sorting techniques?
1. It requires no additional storage space
2. It is scalable
3. It works best for inputs which are already sorted
4. It is faster than any other sorting technique

Explanations :Since selection sort is an in-place sorting algorithm, it does not require additional storage.
Q5.What is the disadvantage of selection sort?
1. It requires auxiliary memory
2. It is not scalable
3. It can be used for small keys
4. None of the mentioned

Explanations :As the input size increases, the performance of selection sort decreases.
Q6.The given array is arr = {3, 4, 5, 2, 1}. The number of iterations in bubble sort and selection sort respectively are,
1. 5 and 4
2. 4 and 5
3. 2 and 4
4. 2 and 5

Explanations :Since the input array is not sorted, bubble sort takes 5 iterations and selection sort takes 4(n-1) iterations.
Q7.What is the best case complexity of selection sort?
1. O(nlogn)
2. O(logn)
3. O(n)
4. O(n2)

Explanations :The best, average and worst case complexities of selection sort is O(n2).
(n-1) + (n-2) + (n-3) + .... + 1 = (n(n-1))/2 ~ (n2)/2.
Q8.Which of the following is not an in-place sorting algorithm?
1. Selection sort
2. Heap sort
3. Quick sort
4. Merge sort

Explanations :Merge sort is not an in-place sorting algorithm.
Q9.The complexity of sorting algorithm measures the …… as a function of the number n of items to be sorter.
1. average time
2. running time
3. average-case complexity
4. case-complexity