What is the best case time complexity of gnome sort?

What is the best case time complexity of gnome sort?
A. O(n)
B. O(n$^{2}$)
C. O(n log n)
D. O(log n)
 
Answer: a
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.
 

Tìm kiếm

Back
Top