Computer Science, asked by kurellasaitejas7023, 1 year ago

How is the bubble sort algorithm different from the modified bubble sort algorithm?

Answers

Answered by dRoid17x
10

Modifying bubble sort is just a way of improving the Time Complexity in the best case of already sorted array. It works as follows:

1. We traverse through the array, comparing and swapping the adjacent elements as we do usually do in bubble sort.

2. If after one traversal no swap occurs it implies that the array is already sorted and we raise a flag and exit from the loop.

This makes the time complexity O(n) in the best-case of bubble sort instead of O(n²)

Similar questions