Insertion sort better than Bubble sort?

后端 未结 5 1898
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-17 18:50

I am doing my revision for the exam.

Would like to know under what condition will Insertion sort performs better than bubble sort given same average case complexity

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-17 19:45

    In the worst case both tend to perform at O(n^2)

    In the best case scenario, i.e., when the array is already sorted, Bubble sort can perform at O(n).

提交回复
热议问题