What is the worst case time complexity of gnome sort?

Ánh Dương

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

Tìm kiếm

Back
Top