How is the bubble sort algorithm different from the modified bubble sort algorithm?
Answers
Answered by
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
Hindi,
6 months ago
Hindi,
6 months ago
Physics,
1 year ago
Biology,
1 year ago
Environmental Sciences,
1 year ago