# Data Structure MCQ - Sorting

Q1.What is an in-place sorting algorithm?

- It needs O(1) or O(logn) memory to create auxiliary locations
- The input is already sorted and in-place
- It requires additional storage
- None of the mentioned

Answer:- (a).

**Explanations :**Auxiliary memory is required for storing the data temporarily.- The input is already sorted
- A large file has to be sorted
- Large values need to be sorted with small keys
- 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.- int min; for(int j=0; j< arr.length-1; j++) { min = j; for(int k=j+1; k<=
- int min; for(int j=0; j< arr.length-1; j++) { min = j; for(int k=j+1; k
- int min; for(int j=0; j< arr.length-1; j++) { min = j; for(int k=j+1; k<=<
- 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.- It requires no additional storage space
- It is scalable
- It works best for inputs which are already sorted
- 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.- It requires auxiliary memory
- It is not scalable
- It can be used for small keys
- None of the mentioned

Answer:- (B).

**Explanations :**As the input size increases, the performance of selection sort decreases.- 5 and 4
- 4 and 5
- 2 and 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.- O(nlogn)
- O(logn)
- O(n)
- O(n2)

Answer:- (D).

(n-1) + (n-2) + (n-3) + .... + 1 = (n(n-1))/2 ~ (n2)/2.

**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.

- Selection sort
- Heap sort
- Quick sort
- Merge sort

Answer:- (D).

**Explanations :**Merge sort is not an in-place sorting algorithm.- average time
- running time
- average-case complexity
- 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.- Insertion sort
- Selection sort
- Heap sort
- None

Answer:- (B).

Copyright © 2022 Shineskill Software Pvt. Ltd., All rights reserved.