Select Page

Sorting: In the data structure, sorting is the process by which you arrange the data in a logical order. This logical order can also be an ascending order or a descending order.

Sorting is related to searching. We search for many things in our life, such as a topic on google, a page in the book, a word in the dictionary, and roll number in the exam hall. Therefore, all these things that happen are sorted so that we can easily search them.

### Types of sorting

There are two types of sorting in the data structure:

1. Internal sorting
2. External sorting

Internal sorting: The data to be sorted in this sorting resides in the main memory. There are the following types of internal sorting.

1. Bubble sort
2. Insertion sort
3. Quick sort
4. Heap sort
5. Selection sort

External sorting: The data to be sorted in this sorting resides in secondary memory. There is so much data in this sorting that it cannot enter the main memory. There is only one type of external sorting called merge sort.

### Bubble sort

Bubble sort is a very easy sorting technique. It compares all the elements one by one. It sorts them based on their values. In this, the two elements of the beginning are compared. If the first element is larger than the second element, it will change both elements’ location, and this comparison will go on till the end.

Complexity table of bubble sort

### Algorithm of bubble sort

The following algorithm is used to implement a bubble sort.

For example: Let’s consider an array A{8. 14, 6, 7, 32, 15}.