SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Quick sort
Quick sortQuick sort
Quick sort
 
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...
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Merge sort algorithm power point presentation
Merge sort algorithm power point presentationMerge sort algorithm power point presentation
Merge sort algorithm power point presentation
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Selection sort
Selection sortSelection sort
Selection sort
 
3.1 bubble sort
3.1 bubble sort3.1 bubble sort
3.1 bubble sort
 
Sorting Techniques
Sorting TechniquesSorting Techniques
Sorting Techniques
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Insertion and merge sort
Insertion and merge sortInsertion and merge sort
Insertion and merge sort
 

Andere mochten auch

Bubblesort Algorithm
Bubblesort AlgorithmBubblesort Algorithm
Bubblesort AlgorithmTobias Straub
 
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 sortasra khan
 
Insertion sort
Insertion sortInsertion sort
Insertion sortalmaqboli
 
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
 
Selection sort
Selection sortSelection sort
Selection sortstella D
 
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
 

Andere mochten auch (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
 
Bubble sort algorithm
Bubble sort algorithmBubble sort algorithm
Bubble sort algorithm
 
Selection sort
Selection sortSelection sort
Selection sort
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Sorting
SortingSorting
Sorting
 
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
 
Selection sort
Selection sortSelection sort
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