WTF is Bubble Sort ?

Bubble sort is a type of sorting algorithm. Its not the best for everything but it does have its uses. It gets its name since it makes the largest values “bubble” to the top. Bubble sort does its job by using pair comparisons. So it takes the current value and compares it to it’s neighbor directly to the right.

Below you can see what I mean. We first take 5 and compare it 3, then ask the question “is 5 greater then 3 ? ” Then if it is, 5 switches places with 3 and if it isn’t then they stay in the same place, and move on to the next value.

BubbleSortEx1

Here you can see a non optimized implementation of it:

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s