in this sorting algorithm multiple swapping


In this sorting algorithm, multiple swapping occurs in one pass. Smaller elements move or 'bubble' up to the top of the list, so the name given to the algorithm.

In this method, adjacent members of list to be sorted are compared. If item over the top is greater than the item instantly below it, then they are swapped. This procedure is carried on until the list is sorted.

The detailed algorithm is like as:

Algorithm: BUBBLE SORT

1. Begin

2. Read the n elements

3. for i=1 to n

              for j=n downto i+1

               if a[j] <= a[j-1]

              swap(a[j],a[j-1])

4. End // of Bubble Sort

Total number of comparisons in Bubble sort will be:

= (N-1) +(N-2) . . . + 2 + 1

= (N-1)*N / 2 =O(N2)

This inefficiency is because of the fact that an item moves only to the next position in each pass.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: in this sorting algorithm multiple swapping
Reference No:- TGS0413898

Expected delivery within 24 Hours