SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Bubble sort
Bubble sortBubble sort
Bubble sortManek Ar
 
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
 
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
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sortDistrict Administration
 
3.1 bubble sort
3.1 bubble sort3.1 bubble sort
3.1 bubble sortKrish_ver2
 
Bubble sort | Data structure |
Bubble sort | Data structure |Bubble sort | Data structure |
Bubble sort | Data structure |MdSaiful14
 
Bubble sorting lab manual
Bubble sorting lab manualBubble sorting lab manual
Bubble sorting lab manualmaamir farooq
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked ListsAfaq Mansoor Khan
 
Different types of Shoring Algorithms with Animation
Different types of Shoring Algorithms with AnimationDifferent types of Shoring Algorithms with Animation
Different types of Shoring Algorithms with AnimationZakaria Hossain
 
Bubblesort Algorithm
Bubblesort AlgorithmBubblesort Algorithm
Bubblesort AlgorithmTobias Straub
 
Selection sort 1
Selection sort 1Selection sort 1
Selection sort 1asmhemu
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureBalwant Gorad
 
Shell sorting
Shell sortingShell sorting
Shell sortingTUC
 
How bubble sort works
How bubble sort worksHow bubble sort works
How bubble sort worksGaurav Kumar
 

Mais procurados (20)

Bubble sort
Bubble sortBubble sort
Bubble 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
 
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...
 
Selection sorting
Selection sortingSelection sorting
Selection sorting
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
 
3.1 bubble sort
3.1 bubble sort3.1 bubble sort
3.1 bubble sort
 
Bubble sort | Data structure |
Bubble sort | Data structure |Bubble sort | Data structure |
Bubble sort | Data structure |
 
Bubble sorting lab manual
Bubble sorting lab manualBubble sorting lab manual
Bubble sorting lab manual
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
 
Different types of Shoring Algorithms with Animation
Different types of Shoring Algorithms with AnimationDifferent types of Shoring Algorithms with Animation
Different types of Shoring Algorithms with Animation
 
Bubblesort Algorithm
Bubblesort AlgorithmBubblesort Algorithm
Bubblesort Algorithm
 
Selection sort 1
Selection sort 1Selection sort 1
Selection sort 1
 
Selection sort algorithm presentation, selection sort example using power point
Selection sort algorithm presentation, selection sort example using power point Selection sort algorithm presentation, selection sort example using power point
Selection sort algorithm presentation, selection sort example using power point
 
Shell sort[1]
Shell sort[1]Shell sort[1]
Shell sort[1]
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Shell sorting
Shell sortingShell sorting
Shell sorting
 
How bubble sort works
How bubble sort worksHow bubble sort works
How bubble sort works
 
Quick sort
Quick sortQuick sort
Quick sort
 

Destaque

Bubble sort a best presentation topic
Bubble sort a best presentation topicBubble sort a best presentation topic
Bubble sort a best presentation topicSaddam Hussain
 
Bubble sort
Bubble sort Bubble sort
Bubble sort rmsz786
 
Selection sort
Selection sortSelection sort
Selection sortJay Patel
 
Selection sort
Selection sortSelection sort
Selection sortasra khan
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sortingKaushal Shah
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithmsmultimedia9
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingEduardo Bergavera
 
3.4 selection sort
3.4 selection sort3.4 selection sort
3.4 selection sortKrish_ver2
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithmNeoClassical
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort ,  Heap SortQuick Sort , Merge Sort ,  Heap Sort
Quick Sort , Merge Sort , Heap SortMohammed Hussein
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-SortTareq Hasan
 

Destaque (20)

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
 
Bubble sort algorithm
Bubble sort algorithmBubble sort algorithm
Bubble sort algorithm
 
Selection sort
Selection sortSelection sort
Selection sort
 
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
 
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
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort ,  Heap SortQuick Sort , Merge Sort ,  Heap Sort
Quick Sort , Merge Sort , Heap Sort
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 

Bubble Sort