# Bubble Sort vs. Selection Sort

The difference between bubble sort and selection sort is that bubble sort is a sorting algorithm that compared adjacent element and then swaps whereas selection sort is a sorting algorithm that select largest number and swap with the last number. Computer programing is a very broad term, in computer programing, the essential concept is sorting. Sorting means to arrange numbers or anything in order; this order can be ascending order or descending order. There are many algorithms for sorting but they most famous and most used algorithms are bubble sort and selection sort. There is a lot of difference between bubble sort and selection sort, but if we talk about the main difference then the main difference between bubble sort and selection sort is that bubble sort is a sorting algorithm that compared adjacent element and then swaps whereas selection sort is a sorting algorithm that select largest number and swap with the last number. The main purpose of sorting is to make the process of searching very easy when things are sorted, searching or any other process becomes much easier.

The simplest form of sorting is bubble sort, bubble sort is a sorting algorithm that compared adjacent element and then swaps. Bubble sort is an iterative algorithm, using iterative, it means that this algorithm will keep on repeating or doing the sorting until it finds what the target is. The logic behind the bubble sort algorithm is elementary it compare the values with all other values, and find the value until the target value is found. If n is the number of elements in an array, then the number of iterations will be n-1. If we need to find the largest number or the position of the largest number, then the position of the largest number will be the nth position. This algorithm is not effective as compared to the other sorting algorithms. Iteration keeps on taking place until the last number; iteration is called comparisons.

For the better performance, bubble sort algorithm is not used, but the algorithm that is used in place of bubble sort is the selection sort algorithm. Selection sort is a sorting algorithm that selects the largest number and swap with the last number. In selection sort, we select one number, and that number is selected on demand for selection whether it is in ascending order or descending order.

## Contents: Difference between Bubble Sort and Selection Sort

### Comparison Chart

 Basis Bubble Sort Selection Sort Meaning Bubble sort is a sorting algorithm that compared adjacent element and then swaps. Selection sort is a sorting algorithm that selects the largest number and swap with the last number. Efficiency Bubble sort is not good in terms of efficiency. Selection sort is best for efficiency. Method Bubble Sort use exchanging method. Selection Sort use selection method. Complexity The complexity of bubble sort is O(n). Selection Sort complexity is O(n^2)

### Bubble Sort

The simplest form of sorting is bubble sort; bubble sort is a sorting algorithm that compared adjacent element and then swaps. Bubble sort is an iterative algorithm, by means of iterative, it means that this algorithm will keep on repeating or doing the sorting until it finds what the target is. The logic behind the bubble sort algorithm is very simple it compare the values with all other values, and find the value until the target value is found. If n is the number of elements in an array, then the number of iterations will be n-1. If we need to find the largest number or the position of the largest number, then the position of the largest number will be the nth position. This algorithm is not effective as compared to the other sorting algorithms. Iteration keeps on taking place until the last number; iteration is called comparisons.

### Selection Sort

For the better performance, bubble sort algorithm is not used, but the algorithm that is used in place of bubble sort is the selection sort algorithm. Selection sort is a sorting algorithm that selects the largest number and swap with the last number. In selection sort, we select one number, and that number is selected on demand for selection whether it is in ascending order or descending order.

Example code for selection sort

### Key Differences

1. Bubble sort is a sorting algorithm that compared adjacent element and then swaps whereas selection sort is a sorting algorithm that selects the largest number and swap with the last
2. Bubble sort is not good in terms of efficiency whereas selection sort is best for efficiency.
3. Bubble Sort use exchanging method whereas selection Sort use selection method.
4. The complexity of bubble sort is O(n) whereas selection Sort complexity is O(n^2).

### Conclusion

Bubble sort and selection sort are thought to be the same algorithm, but there is a lot of difference between bubble sort and selection sort. In this article, there is a clear understanding between the difference between bubble sort and selection sort.