A simple sorting technique that scans the sorted list, starting at the beginning, for the correct insertion point for each of the items from the unsorted list… Read more »
Algorithm-bubble sort
Algorithm BubbleSort(data[],n)
For pass = 1 to n-1
a. Initially in a pass,assume no interchanges
Interchange <- FALSE
b. For(i=0 to (n-pass)
If data[i]>data[i+1]
Then [interchange elements]
i. data[i] <-> data [i+1]
ii. Interchange <- TRUE
c. If (Interchage = FALSE)
Then
Return
End
Explanation
- The algorithm for bubble sort requires a pair of nested loops.
- The outer loop must iterate once for each element in the data set (of size n) while the inner loop iterates n times the first time it is entered, n-1 times the second, and so on.
- Bubble sort is structured so that on each pass through the list the next largest element of the data is moved to its proper place. Therefore, to get all n elements in their correct places, the outer loop must be executed n-1 times.
- The inner loop is executed on each iteration of the outer loop.
- Its purpose is to put the next largest element is being put into place. The inner loop therefore does the comparing and swapping of adjacent elements.
Sorting by MS.K.Abirami
-
BUBBLE SORT
Bubble sort is a sorting algorithm that works by repeatedly stepping through lists that need to be sorted, comparing each pair of adjacent items and swapping them ...Read more »
-
INSERTION SORT
SELECTION SORT
It starts by comparing the entire list for the lowest item and moves it to the #1 position. It then compares the rest of the list for the next-lowest item....Read more »
QUICK SORT
A sorting technique that sequences a list by continuously dividing the list into two parts and moving the lower items to one side and the higher items to the other. … Read more »
BUBBLE SORT
The number of comparison between elements and the number of exchange between elements determine the efficiency of Bubble Sort algorithm.Read more »
Insertion SORT
Insertion sort is also a time taking technique as its complexity is O(n2)Read more »
selection SORT
The number of comparison between elements and the number of exchange between elements determine the efficiency of Bubble Sort algorithm.Read more »
quick SORT
The efficeieny of the quicksort depends on the pivot element. However the pivot element can also be choosen at random order or from the last element of the array