# Bubble Sort Algorithm Assignment Help

Bubble sort is an easy as well as well-known sorting algorithm. Its primary application would be to help to make an introduction to the sorting algorithms. Bubble sort belongs to O(n2) sorting algorithms, which makes it quite inefficient with regard to sorting large data volumes. Bubble sort is stable as well as adaptive.

## Algorithm

• Evaluate every set of adjacent elements from the beginning of an array as well as, when they have been in reversed order, swap them.
• If at least one swap has been done, repeat step 1.

You can imagine that on every step big bubbles float to the surface and stay there. At the step, when no bubble moves, sorting stops.

### Bubble sort Example:

An example of sorting an array: Sort {5, 1, 12, -5, 16} using bubble sort.

## Complexity analysis

Average as well as worst case complexity associated with bubble sort is O(n2). Additionally, this can make O(n2) swaps within the worst case. Bubble sort is adaptive. It means that for almost sorted array this provides O(n) estimation. Avoid implementations that do not check when the array is already sorted on every step (any swaps made). This particular examine is essential, to be able to preserve adaptive property.