Algorithms | Sorting | Question 10
What is the best time complexity of bubble sort?
Explanation: The bubble sort is at its best if the input data is sorted. i.e. If the input data is sorted in the same order as expected output. This can be achieved by using one boolean variable. The boolean variable is used to check whether the values are swapped at least once in the inner loop.
Consider the following code snippet:
Please observe that in the above code, the outer loop runs only once.
Quiz of this Question
My Personal Notes arrow_drop_up
Please Login to comment...