/* */ 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
  3. It requires additional storage
  4. None of the mentioned

Answer:- (a).
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

Answer:- (C).
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<=<

Answer:- (A).
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

Answer:- (A).
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

Answer:- (B).
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

Answer:- (A).
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)

Answer:- (D).
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

Answer:- (D).
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

Answer:- (B).
Explanations :The complexity of sorting algorithm measures the running time as a function of the number n of items to be sorter.
Q10.Consider the situation in which assignment operation is very costly. Which of the following sorting algorithm should be performed so that the number of assignment operations is minimized in general?
  1. Insertion sort
  2. Selection sort
  3. Heap sort
  4. None

Answer:- (B).