Compare the Difference Between Similar Terms

Difference Between

Home / Technology / IT / Programming / Difference Between Bubble Sort and Selection Sort

Difference Between Bubble Sort and Selection Sort

June 29, 2011 Posted by Indika

Bubble Sort vs Selection Sort

Bubble sort is a sorting algorithm that operates by going through the list to be sorted repeatedly while comparing pairs of elements that are adjacent. If a pair of elements is in the wrong order they are swapped to place them in the correct order. This traversal is repeated until no further swaps are required. Selection sort is also a sorting algorithm, which starts by finding the minimum element in the list and swapping it with the first element. This process is repeated for the remainder of the list by placing swapped elements in order.

What is Bubble Sort?

Bubble sort is a sorting algorithm that operates by going through the list to be sorted repeatedly while comparing pairs of elements that are adjacent. If a pair of elements is in the wrong order they are swapped to place them in the correct order. This traversal is repeated until no further swaps are required (which means that the list is sorted). Since the smaller elements in the list come to the top as a bubble comes to the surface, it is given the name bubble sort. Bubble sort is a very simple sorting algorithm but it has an average case time complexity of O(n2) when sorting a list with n elements. Due to this, bubble sort is not suitable for sorting lists with a large number of elements. But due its simplicity, bubble sort is taught during introductions to algorithms.

What is Selection Sort?

Selection sort is also another sorting algorithm that starts by finding the minimum element in the list and swapping it with the first element. Then the minimum element is found from the remainder of the list (from the second element until the last element in the list) and swapped with the second element. This process is repeated for the remainder of the list by placing swapped elements in order. So in selection sort, at any step of the algorithm, the list is divided in to two parts where one part contains sorted elements and the other part contains unsorted elements. As the algorithm proceeds, the sorted list grows from left to right. Selection sort also has an average case time complexity of O(n2). Therefore it is also not suitable for sorting large lists.

What is the difference between Bubble Sort and Selection Sort?

Even though both the bubble sort and selection sort algorithms have average case time complexities of O(n2), bubble sort is almost all time outperformed by the selection sort. This is due to the number of swaps needed by the two algorithms (bubble sorts needs more swaps). But due to the simplicity of bubble sort, its code size is very small. Stability is another difference in these two algorithms. A stable sorting algorithm, is a sorting algorithm that retains order of records if the list contains elements with an equal value. In that sense, selection sort is not a stable algorithm whereas bubble sort is a stable algorithm.

Related posts:

Difference Between Java and JavaScript Difference Between JSF2 and Seam3 Difference Between Inheritance and Containership Difference Between Algorithm and Pseudocode Difference Between Classes and Structures

Filed Under: Programming Tagged With: Bubble sort, Selection sort, sorting algorithms, stable sorting algorithm

About the Author: Indika

Indika, BSc.Eng, MSECE Computer Engineering, PhD. Computer Science, is an Assistant Professor and has research interests in the areas of Bioinformatics, Computational Biology, and Biomedical Natural Language Processing.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Request Article

Featured Posts

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and SARS

Difference Between Coronavirus and SARS

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Covid 19

Difference Between Coronavirus and Covid 19

You May Like

Difference Between Relational and Transactional Selling

Difference Between Modernization Theory and Dependency Theory

Difference Between Modernization Theory and Dependency Theory

What is the Difference Between Mechanical and Biological Transmission

What is the Difference Between Mechanical and Biological Transmission

Difference Between Digital Signature and Electronic Signature

Difference Between Digital Signature and Electronic Signature

Difference Between Pollen Tube and Style

Difference Between Pollen Tube and Style

Latest Posts

  • What is the Difference Between Omphalocele and Gastroschisis
  • What is the Difference Between Autonomic and Somatic Reflexes
  • What is the Difference Between Plagiocephaly and Craniosynostosis
  • What is the Difference Between Coconut Oil and Virgin Coconut Oil
  • What is the Difference Between Wintrobe and Westergren Tube
  • What is the Difference Between Coarctation and Hypoplastic Aortic Arch
  • Home
  • Vacancies
  • About
  • Request Article
  • Contact Us

Copyright © 2010-2018 Difference Between. All rights reserved. Terms of Use and Privacy Policy: Legal.