# Bubble Sort

Bubble sort is a basic algorithm for arranging a string of numbers or other elements in the correct order. The method works by examining each set of adjacent elements in the string, from left to right, switching their positions if they are out of order. The algorithm then repeats this process until it can run through the entire string and find no two elements that need to be swapped.

## What Does a Bubble Sort Look Like?

If a programmer or analyst wanted to arrange a series of numbers in ascending order, the bubble sort approach would look like the example pictured here.

The algorithm would review two items at a time, rearrange those not already in ascending order from left to right, and then continue to cycle through the entire sequence until it completed a pass without switching any numbers.

## How Do Computer Programmers Use Bubble Sort?

Computer programmers use bubble sort to arrange a sequence of numbers in the correct order. Because it is the simplest type of sorting algorithm, bubble sort does not get used much in real-world computer science. Its most common uses for programmers include the following:

### 1. A way to learn basic sorting

Bubble sort works as a method for teaching new programmers how to sort data sets because the algorithm is straightforward to understand and implement.

### 2. A methodology for sorting tiny datasets

Because it has to repeatedly cycle through the entire set of elements, comparing only two adjacent items at a time, bubble sort is not optimal for more massive datasets. But it can work well when sorting only a small number of elements.

### 3. A sorting methodology for datasets that are mostly in order already

Finally, some computer scientists and data analysts use the algorithm as a final check for datasets they believe are already in nearly sorted order.

## How Can Product Managers Use Bubble Sort?

One of the product manager’s most essential and difficult responsibilities is to weigh competing initiatives and decide where to focus the team’s limited time and resources.

For example, product teams weigh the costs vs. benefits of backlog items to decide which items will earn a spot on the product roadmap. They also assign story points to each backlog item to determine the amount of effort and time that the item will take to complete.

For all of these types of scoring initiatives, product managers must then apply a sorting approach to determine how to prioritize their team’s work. For this type of sorting, a simple bubble sort method makes sense.

## What are Other Sorting Algorithms Besides Bubble Sort?

Bubble sort is only one of many algorithms for sorting datasets. Others include:

• Selection sort
• Insertion sort
• Merge sort
• Quick sort
• Heap sort
• Bucket sort