68.0k views
4 votes
What is the perpose of the boolean variable swaps in this buble sort algorithm

User Mike Hay
by
6.8k points

1 Answer

7 votes

Answer:

“Bubble Up” algorithm will move largest

value to its correct location (to the

right/end of array)

• Repeat “Bubble Up” until all elements are

correctly placed:

– Maximum of N-1 times

– Can finish early if no swapping occurs

• We reduce the number of elements we

compare each time one is correctly placed

User Mooreds
by
7.1k points