Insertion sort vs Bubble Sort Algorithms

后端 未结 11 898
名媛妹妹
名媛妹妹 2020-12-07 08:51

I\'m trying to understand a few sorting algorithms, but I\'m struggling to see the difference in the bubble sort and insertion sort algorithm.

I know both are O(n

11条回答
  •  爱一瞬间的悲伤
    2020-12-07 09:33

    insertion sort:

    1.In the insertion sort swapping is not required.

    2.the time complexity of insertion sort is Ω(n)for best case and O(n^2) worst case.

    3.less complex as compared to bubble sort.

    4.example: insert books in library, arrange cards.

    bubble sort: 1.Swapping required in bubble sort.

    2.the time complexity of bubble sort is Ω(n)for best case and O(n^2) worst case.

    3.more complex as compared to insertion sort.

提交回复
热议问题