SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Bubble sort | Data structure |
Bubble sort | Data structure |Bubble sort | Data structure |
Bubble sort | Data structure |MdSaiful14
 
Searching Techniques and Analysis
Searching Techniques and AnalysisSearching Techniques and Analysis
Searching Techniques and AnalysisAkashBorse2
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure NUPOORAWSARMOL
 
Selection sort
Selection sortSelection sort
Selection sortamna izzat
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...Umesh Kumar
 
3.2 insertion sort
3.2 insertion sort3.2 insertion sort
3.2 insertion sortKrish_ver2
 
Searching & Sorting Algorithms
Searching & Sorting AlgorithmsSearching & Sorting Algorithms
Searching & Sorting AlgorithmsRahul Jamwal
 
Selection sort
Selection sortSelection sort
Selection sortstella D
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structureschauhankapil
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeManishPrajapati78
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Muhammad Hammad Waseem
 
Insertion sort
Insertion sortInsertion sort
Insertion sortalmaqboli
 

Tendances (20)

Bubble sort | Data structure |
Bubble sort | Data structure |Bubble sort | Data structure |
Bubble sort | Data structure |
 
Selection sort
Selection sortSelection sort
Selection sort
 
Searching Techniques and Analysis
Searching Techniques and AnalysisSearching Techniques and Analysis
Searching Techniques and Analysis
 
Insertion Sorting
Insertion SortingInsertion Sorting
Insertion Sorting
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Selection sort
Selection sortSelection sort
Selection sort
 
Searching and sorting
Searching  and sortingSearching  and sorting
Searching and sorting
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
3.2 insertion sort
3.2 insertion sort3.2 insertion sort
3.2 insertion sort
 
Searching & Sorting Algorithms
Searching & Sorting AlgorithmsSearching & Sorting Algorithms
Searching & Sorting Algorithms
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
 
Selection sort
Selection sortSelection sort
Selection sort
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 

En vedette

En vedette (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 - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
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
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
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
 

Bubble Sort