Search code examples
bubble-sort

Why need bubble sorting?


After learning bubble sorting, I learned other sorting. And then I thought, there are other good sorting, do we need bubble sorting?

In the worst case, the Time Complexity is O(n²) Even in the best case, Time Complexity is O(n²) Is there a reason why need this kind of bubble sorting?


Solution

  • Bubble sort is easy to understand and implement. It is not very efficient, but it can be useful in certain situations, such as when the data is nearly sorted or when the input is very small.

    Bubble sort can be easily adapted to sort lists of data that are stored in other data structures, such as linked lists

    Bubble sort is a stable sorting algorithm, which means that it preserves the relative order of items with equal keys.