We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Sorting: Bubble Sort
- Discussions
Sorting: Bubble Sort
Sorting: Bubble Sort
Sort by
recency
|
404 Discussions
|
Please Login in order to post a comment
Bubble sort swaps every time a larger number is to the left of a smaller number. Therefore, if we count the number of times a larger number is left of a smaller one, we have the number of swaps.
This does not improve time complexity, but allows us to avoid swapping entirely. In practice, it should be more efficient, for the same reason insertion and selection sort are "better" than bubble sort despite the same time complexity.
Having a question where the formatting of the answer needs to be exact is misleading. I had an extra space
Compiler Message
Wrong Answer
Input (stdin)
Your Output (stdout)
Expected Output
Python: