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

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

1. Time complexity of sleep sort can be approximated to be ___________
A) O(n + max(input))
B) O(n2)
C) O(n log n + max(input))
D) O(n log n)

Explanation: As the sleep() function uses a priority queue to build multiple threads, insertion takes n log n time. As all of the elements wake up, the performance is also received. The length of time is proportional to the maximum (input). As a result, the time complexity is roughly O(n log n + max(input)).

2. Sleep sort can be preferred over which of the following sorting algorithms for large number of input elements?
A) Quick sort
B) Bubble sort
C) Selection sort
D) No sorting algorithm is preferred

Explanation: Sleep sort is not favoured over any of the other sorting algorithms because it does not always produce right results. As a result, sleep sorting is not a reliable sorting method.

3. Auxiliary space requirement of sleep sort is ___________
A) O(n)
B) O(1)
C) O(max(input))
D) O(log n)

Explanation: The OS controls all of the main processes involved in sleep sorting. As a result, sorting the elements does not necessitate any additional space.

4. Sleep sort does gives a correct output when ___________
A) any input element is negative
B) input array is reverse sorted
C) any input element is positive
D) when there is a very small number to the left of very large number

Explanation: When the array elements are positive, sleep sort produces a sorted output. However, if any of the above-mentioned cases do not occur, we can not get the desired result. As a result, sleep sort is a very unreliable sorting method.

5. Which of the following sorting algorithm is most closely related to the OS?
A) gnome sort
B) sleep sort
D) bogo sort

Explanation: The operating system is the most closely related to sleep type. Since the majority of the algorithm’s major steps take place at the OS’s heart, this is the case.

6. Sleep sort is an in-place sorting technique.
A) True
B) False

Explanation: The majority of the main steps of the sleep sort take place in the background, making it an in-place sorting technique. As a result, sorting the input does not require any additional space.

7. Which of the following header file is a must to implement sleep sort algorithm?
A) string.h
B) math.hw
C) bios.h
D) windows.h

Explanation: We’ll need functions like WaitForMultipleObjects() and _beginthread to implement the sleep sort algorithm (). These are included in the windows.h header format.

8. Sleep sort does not work for ___________
A) negative numbers
B) large numbers
C) small numbers
D) positive numbers

Explanation: For negative numbers, the sleep sort algorithm fails. This is due to the fact that thread cannot sleep for an extended period of time.

9. In how many comparisons does the array arr={1,4,2,3,5} gets sorted if we use sleep sort?
A) 5
B) 3
C) 1
D) 0

Explanation: Sleep sort puts the array’s different elements to sleep for a period of time equal to their magnitude. As a result, there is no need to conduct any comparisons to sort the list.

10. Sleep sort works by ___________
A) making elements to sleep for a time that is proportional to their magnitude
B) making elements to sleep for a time that is inversely proportional to their magnitude
C) partitioning the input array
D) dividing the value of input elements

Explanation: And element in the sleep sort is forced to sleep for a period of time proportional to its magnitude. The elements are then printed in the order that they awaken.

11. Sleep sort code cannot compile online because ___________
A) it has very high time complexity
B) it has very high space complexity
C) it requires multithreading process
D) online compilers are not efficient

Explanation: To put the elements to sleep, a multithreading process is needed. Since this process occurs in the background at the OS’s heart, it cannot be compiled using an online compiler.

We create separate threads for each of the elements in the input array in this algorithm, and then each thread sleeps for a period of time proportional to the value of the corresponding array element. As a result, the thread with the least amount of sleeping time is the first to wake up, and the number is written, followed by the second least part, and so on. After a long time, the largest element awakens, and the element is printed last. As a result, the output is sorted. This multithreading occurs in the background and at the centre of the OS. We have no way of knowing what’s going on in the background, so this is a “mysterious” sorting algorithm.