Efficency of Insertion Sort vs Bubble sort vs Selection sort?

后端 未结 3 437
野的像风
野的像风 2021-01-07 13:41

I have written down that Insertion Sort is faster than Selection Sort, which is faster than Bubble Sort, and that their running time for all 3 are O(n^2), but what can I say

3条回答
  •  被撕碎了的回忆
    2021-01-07 14:26

    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.

提交回复
热议问题