SlideShare a Scribd company logo
1 of 78
Bubble Sort


By: Yoo Lee & Gabrielle Ortiz
         Block 2A
Basic Introduction:
Bubble Sort is a simple yet effective sorting algorithm.
Data is placed adjacent to each other.
The sort starts from one end (the beginning), compares
2 adjacent data, and swaps them if they are in the
wrong order.
It moves on down the list and continues doing so.
When it reaches the end of the data, it starts over until
all the data is in the right order.
*As easy as the Bubble Sort is, it is sometimes
ineffective if there is a lot of data.
When to Use Bubble Sort


Not much use in the real world, but is a great learning tool
because it’s easy to understand and fast to implement.
Use when a fast algorithm is needed to sort:
   1.) an extremely small set of data (Ex. Trying to get the books on
   a library shelf back in order.)
                      or
   2.) a nearly sorted set of data. (Ex. Trying to decide which
   laptop to buy, because it is easier to compare pairs of laptops
   one at a time and decide which you prefer, than to look at them
   all at once and decide which was best.)
When to Not Use Bubble Sort


When dealing with a large set of data.

When you are looking for a quick algorithm.
Compared to other sorting algorithm, bubble sort is
really slow.
EXAMPLE




LET’S MIX IT UP!!
EXAMPLE
EXAMPLE
EXAMPLE




Now this box will go through the list, swapping
numbers if the one previous is greater than the
one after, until the numbers are in order.
EXAMPLE
EXAMPLE




WRONG ORDER!
SWITCH!
EXAMPLE




That’s better.
EXAMPLE




Moving on.
EXAMPLE




WRONG ORDER!
SWITCH!
EXAMPLE




WRONG ORDER!
SWITCH!
EXAMPLE
EXAMPLE




Moving on.
EXAMPLE
EXAMPLE
EXAMPLE




WRONG ORDER!
SWITCH!
EXAMPLE




WRONG ORDER!
SWITCH!
EXAMPLE
EXAMPLE




Moving on.
EXAMPLE
EXAMPLE




WRONG ORDER!
SWITCH!
EXAMPLE
EXAMPLE




Moving on.
EXAMPLE
EXAMPLE




WRONG ORDER!
SWITCH!
EXAMPLE
EXAMPLE
EXAMPLE




Moving on.
EXAMPLE
EXAMPLE




Now the box has reached the end of the line
of numbers.
It will go back to the beginning and restart
the process
EXAMPLE
EXAMPLE




WRONG ORDER!
SWITCH!
EXAMPLE
EXAMPLE
EXAMPLE




Moving on.
EXAMPLE
EXAMPLE




WRONG ORDER!
SWITCH!
EXAMPLE
EXAMPLE




Moving on.
EXAMPLE
EXAMPLE




WRONG ORDER!
SWITCH!
EXAMPLE
EXAMPLE




Moving on.
EXAMPLE
EXAMPLE




WRONG ORDER!
SWITCH!
EXAMPLE
EXAMPLE




Moving on.
EXAMPLE
EXAMPLE




HEY it’s already in the right
order! No need to change.
EXAMPLE
EXAMPLE




HEY it’s already in the right
order! No need to change.
EXAMPLE
EXAMPLE




WRONG ORDER!
SWITCH!
EXAMPLE
EXAMPLE




Moving on.
EXAMPLE
EXAMPLE




HEY it’s already in the right
order! No need to change.
EXAMPLE
EXAMPLE




HEY it’s already in the right
order! No need to change.
EXAMPLE
EXAMPLE




HEY it’s already in the right
order! No need to change.
EXAMPLE
EXAMPLE




WRONG ORDER!
SWITCH!
EXAMPLE
EXAMPLE




Moving on.
EXAMPLE
EXAMPLE




HEY it’s already in the right
order! No need to change.
EXAMPLE
EXAMPLE




HEY it’s already in the right
order! No need to change.
EXAMPLE
EXAMPLE




HEY it’s already in the right
order! No need to change.
EXAMPLE
EXAMPLE




HEY it’s already in the right
order! No need to change.
EXAMPLE




YAY WE’RE DONE!
Links Used

http://stackoverflow.com/questions/276113/what-is-a-bubble-sort-good-
for

http://www.stoimen.com/blog/2012/02/20/computer-algorithms-
bubble-sort/


http://vimeo.com/4315697


http://www.algolist.net/Algorithms/Sorting/Bubble_sort

More Related Content

What's hot (20)

Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Insertion sort
Insertion sort Insertion sort
Insertion sort
 
Lecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic SortingLecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic Sorting
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Array data structure
Array data structureArray data structure
Array data structure
 
Selection sort
Selection sortSelection sort
Selection sort
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
 
Linked list
Linked listLinked list
Linked list
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort ,  Heap SortQuick Sort , Merge Sort ,  Heap Sort
Quick Sort , Merge Sort , Heap Sort
 
Shell sort
Shell sortShell sort
Shell sort
 
How bubble sort works
How bubble sort worksHow bubble sort works
How bubble sort works
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Selection sort
Selection sortSelection sort
Selection sort
 
Stack project
Stack projectStack project
Stack project
 
Linked list
Linked listLinked list
Linked list
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
 

Viewers also liked

Viewers also liked (20)

Bubblesort Algorithm
Bubblesort AlgorithmBubblesort Algorithm
Bubblesort Algorithm
 
Bubble sort a best presentation topic
Bubble sort a best presentation topicBubble sort a best presentation topic
Bubble sort a best presentation topic
 
Bubble sort
Bubble sort Bubble sort
Bubble sort
 
Selection sort
Selection sortSelection sort
Selection sort
 
3.1 bubble sort
3.1 bubble sort3.1 bubble sort
3.1 bubble sort
 
Bubble sort algorithm
Bubble sort algorithmBubble sort algorithm
Bubble sort algorithm
 
Selection sort
Selection sortSelection sort
Selection sort
 
Sorting
SortingSorting
Sorting
 
Merge sort
Merge sortMerge sort
Merge sort
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
 
3.4 selection sort
3.4 selection sort3.4 selection sort
3.4 selection sort
 
Quick Sort
Quick SortQuick Sort
Quick Sort
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
 
The selection sort algorithm
The selection sort algorithmThe selection sort algorithm
The selection sort algorithm
 
Mergesort
MergesortMergesort
Mergesort
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 
Quick sort
Quick sortQuick sort
Quick sort
 

Bubble Sort