Timsort Multiple choice Questions and Answers (MCQs)

YOU CAN DOWNLOAD 200+ SUBJECTS PDF BOOK FOR COMPETITIVE EXAMINATIONS

CLICK HERE TO DOWNLOAD

Timsort Multiple choice Questions and Answers (MCQs)

Question 11 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Which of the following algorithm is implemented internally in java when we use function arrays.sort()?
A
intro sort
B
quick sort
C
tim sort
D
merge sort
Question 11 Explanation: 
Java makes use of Tim sort internally for implementing arrays.sort(). It is mainly due to the fastness of this algorithm in comparison to other comparison based sorts.

Question 12 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Why is insertion sort preferred over other sorting algorithms (like selection sort, bubble sort etc.) for Tim sort implementation?
A
Because insertion sort is faster and adaptive
B
Because insertion sort requires less space
C
Because insertion sort is easy to implement
D
Because insertion sort is easy to understand
Question 12 Explanation: 
When small arrays need to be sorted then insertion sort proves to be the best choice . Also, it is adaptive so it performs better than others when the given array is fully/partially sorted.

Question 13 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
In which case will tim sort will work as an insertion sort?
A
when no. of elements are less than 64
B
when no. of elements are greater than 64
C
when no. of elements are less than size of run
D
when no. of elements are less than 32
Question 13 Explanation: 
Tim sort uses a hybrid of insertion and merge sort. It reduces to insertion sort when the size of array is less than the size of run as insertion sort is efficient in sorting small arrays.

Question 14 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the usual size of a run in tim sort?
A
32
B
less than 32
C
32-64 depending on size of the array
D
64
Question 14 Explanation: 
Usually the size of the run is chosen somewhere between 32 and 64. The size of run is preferably chosen in powers of 2 in order to maintain balance while merging the sorted runs.

Question 15 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What will be the output of the given Java code?

import java.util.Arrays; public class SortExample { 	public static void main(String[] args) 	{ 		// Our arr contains 8 elements  		int[] arr = {10, 7, 9, 5, 8, 4}; 		Arrays.sort(arr); 		System.out.printf(Arrays.toString(arr)); 	} }
A
[4, 5, 7, 8, 9, 10]
B
[10, 9, 8, 7, 5, 4]
C
4, 5, 7, 8, 9, 10
D
error
Question 15 Explanation: 
The given program sorts the input in ascending order by using the function Arrays.sort(). It uses Tim sort internally.

There are 15 questions to complete.