# Library Sort – Multiple Choice Questions and Answers (MCQs)

This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “Library Sort”.

1. Library sort is a comparison based sort.
A) true
B) false

Explanation: In order to insert elements at the correct index in a library sort, we must compare them. As a result, we can assume that it sorts the array using comparisons. As a result, it is classified as a comparison-based sort.

2. What is the average case time complexity of library sort?
A) O(n)
B) O(n log n)
C) O(n2)
D) O(log n)

Explanation: Library sort reduces the time complexity of the array by using binary search to insert elements in the sorted segment. As a result, library sort has an average time complexity of O. (n log n).

3. What is the best case time complexity of library sort?
A) O(n)
B) O(n log n)
C) O(n2)
D) O(log n)

Explanation: The best-case library sort time complexity is O. (n). When the input is already/almost sorted, this error occurs.

4. What is the worst case time complexity of library sort?
A) O(n)
B) O(n log n)
C) O(n2)
D) O(log n)

Explanation: The time complexity of library sort is the same as that of insertion sort in the worst-case scenario. In the worst-case scenario, the time complexity is O. (n2).

5. Which of the following is an alternate name of library sort?
A) gapped insertion sort
B) binary insertion sort
c) recursive insertion sort
d) binary gap sort

Explanation: Since it uses insertion sort with gaps between successive elements, library sort is also known as gapped insertion sort. These holes make it possible to insert items quickly.

6. What is the advantage of library sort over insertion sort?
A) Library sort has a better average time complexity
B) Library sort has a better space complexity
C) Library sort has better best case time complexity
D) Library has better worst case time complexity

Explanation: Since library sort uses binary search to find the index where the element must be inserted in the sorted list, it has a lower average time complexity than insertion sort. This speeds up the process.

7. What is the auxiliary space complexity of library sort?
A) O(n)
B) O(1)
C) O(n log n)
D) O(n2)

Explanation: Library sort necessitates O auxiliary room (n). The differences that exist between successive elements take up this space.

8. Which of the following is an adaptive sorting algorithm?
A) library sort
B) merge sort
C) heap sort
D) selection sort

Explanation: An adaptive algorithm is library form. The reason for this is that when the input array is almost sorted, the algorithm’s time complexity increases.

9. Which of the following sorting algorithm is not in place?
A) library sort
B) quick sort sort
C) heap sort
D) gnome sort

Explanation: The only algorithm not in use among the available options is library type. The reason for this is that the auxiliary space needed by library sort is O. (n).

10. Which of the following is not true about library sort?
A) it uses binary search and insertion sort in its implementation
B) gaps are created between successive elements in order to ensure faster insertion
C) array needs to be re balanced after every insertion
D) it is an in place sorting algorithm

Explanation: Since it needs O(n) auxiliary space, library sort is not an in place sorting algorithm. After each addition, the array must be rebalanced to ensure that gaps exist between each successive element.

11. Which of the following is a disadvantage of library sort when compared to insertion sort?
A) library sort has greater time complexity
B) library sort has greater space complexity
C) library sort makes more comparisons
D) it has no significant disadvantage

Explanation: The downside of library sort is that it uses O(n) auxiliary space, while insertion sort uses constant auxiliary space.

12. Library sort is an online sorting algorithm.
A) true
B) false

Explanation: In order to sort the list, library sort does not require all of the input data at the start. It instead creates a partial solution at each point, obviating the need to consider future elements. As a result, it’s an online sorting algorithm, similar to insertion sort.

13. Library sort is a modified version of which of the following sorting algorithm?
A) Bubble sort
B) selection sort
C) insertion sort
D) quick sort

Explanation: Insertion sort and binary search are needed in the library sort code. As a result, it’s a tweaked version of insertion type.

14. Which of the following sorting algorithm is stable?
A) Selection sort
B) Quick sort
C) Library sort
D) Heap sort

Explanation: The only algorithm that is stable among the options is library form. Since the elements with similar values appear in the output array in the same order as they did in the input array, this is the case.

15. Which of the following sorting algorithm requires the use of binary search in their implementation?
A) radix sort
B) library sort
C) odd-even sort
D) bead sort

Explanation: A binary search algorithm is used to filter the library. It’s used to locate the correct index in the array where the element should go. Following that, the array is rebalanced after the element is inserted.

The gapped insertion sort, also known as library sort, is a sorting algorithm that uses an insertion sort but with gaps in the array to speed up subsequent insertions. The name comes from an analogy: imagine a librarian storing his books alphabetically on a long shelf, beginning with the As at the left end and going to the right until the end of the Zs, with no gaps between the books. If the librarian acquires a new book that belongs in the B section, he will have to transfer every book from the centre of the Bs all the way down to the Zs in order to make room for the new book until he finds the appropriate space in the B section.