Back to Browse

Bubble Sort Technique in Data Structure Using C

9 views
Mar 22, 2021
15:15

The bubble sort is the oldest and simple sort in use. The bubble sorting is also the slowest. The bubble sort works by comparing each item in the list with the element next to it and if element is smaller than next element then swapping it, continue this process to find first large element at the last element to list and smaller element to come beginning to the list. This is the first iteration and continues this process until you can find whole list as sorting in ascending or descending order. Assume that an array x content five elements. The bubble sort algorithm works as follows way: 1. In the first iteration the 0th element 9 is compared with 1st element 7 and since 9 is greater than 7, they are interchanged. 2. Now the 1st element 9 is compared with 2nd element 5 and since 9 is grater than 5, they are interchanged. 3. Now the 2nd element 9 is compared with 3rd element 8 and since 9 is grater than 8, they are interchanged. 4. Now at last of the first iteration, 3rd 9 is compared with 4th element 3 and since 9 is greater than 3, they are interchanged. 5. These same processes apply on rest of other iterations. 6. This process is repeated until (N-2) element is compared with (N-1)element. During the comparison if (N-2) element is found to be greater than the (N-1) ,then they are interchanged, otherwise not. 7. At the end of the first iteration, the (N-1) element hold the largest element. Advantages of Bubble sort are as follow: 1. It is very simple sorting technique. 2. It is very easy to implementation. 3. First iteration table we find first large value at last element. Disadvantage of Bubble sort are as follow: 1. Large list not handing by this sorting technique. 2. It is very inefficient sorting technique.

Download

0 formats

No download links available.

Bubble Sort Technique in Data Structure Using C | NatokHD