Skip to main content

Posts

Showing posts from February, 2017

Bubble Sort

               Bubble Sort is a sorting algorithm that works by comparing each pair of adjacent items and swapping them if they are in wrong order repeatedly till the list is sorted.               Bubble sort is also referred to as sinking sort or comparison sort . The algorithm is named for the way smaller or larger elements “bubble“ to the top of the list.              Bubble sort algorithm is the simplest algorithm for sorting but it is too slow and impractical for most problems. Bubble Sort Algorithm Step 1: Enter how many numbers(n) to sort. Step2: Enter all numbers and store it in array a[]. Step3: Make a key starting with second element of an array a[]. Step4: Now compare the [key-1] element of an array a[] with [key] element of an array a[]. Step5: For ascending order if the [key-1] element of an array a[] is greater than [key] element of an array a[] then swap the respective elements of an array a[]. Step6:Move the key to right to next element