Bubble Sort

Write a function ‘bubble_sort(arr)’ which will sort an array of integers using the “bubble sort” methodology.  (http://en.wikipedia.org/wiki/Bubble_sort)


First and foremost, understand the difference between insertion sort and bubble sort.

Insertion sort:  Faster because it compares a value against the entire array and places it in the right location in one go.  (The .sort method does this).


Bubble sort: Slower because it compares only against the next index, thus resulting in more comparison steps before ending up in the right location.



Test Cases:



Bubble Sort

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