Insertion sort better than Bubble sort?

后端 未结 5 2011
佛祖请我去吃肉
佛祖请我去吃肉 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:27

    The advantage of bubblesort is in the speed of detecting an already sorted list:

    BubbleSort Best Case Scenario: O(n)

    However, even in this case insertion sort got better/same performance.

    Bubblesort is, more or less, only good for understanding and/or teaching the mechanism of sortalgorithm, but wont find a proper usage in programming these days, because its complexity

    O(n²)

    means that its efficiency decreases dramatically on lists of more than a small number of elements.

提交回复
热议问题