# Gnome Sort Multiple choice Questions and Answers (MCQs)

## Gnome Sort Multiple choice Questions and Answers (MCQs)

 Question 6 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Gnome sort uses which of the following method to implement sorting?
 A Merging B Partitioning C Selection D Exchanging
Question 6 Explanation:
Gnome sort implements sorting by exchanging the adjacent elements which are out of order. Thus its method of sorting is called exchanging.

 Question 7 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the best case time complexity of gnome sort?
 A O(n) B O(n2) C O(n log n) D O(log n)
Question 7 Explanation:
When the input array is already sorted then in that case there will be no need to decrease the value of the index variable at any stage. So only O(n) time is required in this case as we keep on increasing its value after each iteration.

 Question 8 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Select the appropriate code that performs gnome sort.
 A while (index > n) { if (index == 0) index++; if (arr[index] <= arr[index - 1]) index++; else { swap( B while (index < n) { if (index == 0) index++; if (arr[index] <= arr[index - 1]) index++; else { swap(arr C while (index < n) { if (index == 0) index++; if (arr[index] >= arr[index - 1]) index++; else
Question 8 Explanation:
The first if statement increments the value of index if found to be 0 so that comparison can take place for this element. Second if statement checks whether the adjacent pair of elements are in order or not. If found out of order they are swapped under the else statement and index is decremented.

 Question 9 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the worst case time complexity of gnome sort?
 A O(n) B O(n2) C O(n log n) D O(log n)
Question 9 Explanation:
Worst case occurs when the input array is reverse sorted as it will have the maximum number of decrements while sorting. This causes the algorithm to have a time complexity of O(n2) in this case.

 Question 10 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the average case time complexity of gnome sort?
 A O(n) B O(n2) C O(n log n) D O(log n)
Question 10 Explanation:
In gnome sort the loop has to take one step backwards every time any adjacent pair of elements is out of place which causes it to have time complexity of O(n2) on an average.

There are 10 questions to complete.