Bubble Sort Tathagata Mukherjee

ABSTRACT repeated until there are no swaps in which case provide a way to arrange a the algorithm stops as the list is then in the series of numbers or letters in some predefined sorted order. The algorithm gets its name from order based on some measurable quantity in the fact that the smaller numbers bubble up the the numbers or letters. Thus we may arrange a list as the algorithm proceeds. The pseudocode series of numbers according to their values in for the algorithm is given below: an increasing order or we may arrange the letters according to decreasing order of their BubbleSort( List lst of n elements) ASCII values using sorting. In this paper we { will describe a simple and easy to implement swapFlag = false; called Bubble Sort. for( i=0 to n do){ if(lst[i] > lst[i+1]) then{ INTRODUCTION swap lst[i] and lst[i+1]; Given a list of n numbers or letters the swapFlag=true; objective of any sorting algorithm is to arrange } // end if the same in a particular order where the } // end for ordering is done based on some intrinsic } // end BubbleSort property of the inputs. The simplest way to sort a list of input values is to compare them ILLUSTRATION pairwise and obtain the proper ordering. Let us illustrate the algorithm on the list Sorting algorithms that achieve their goal by <43751>. The different steps and the outcomes comparison are called comparison based are shown below: sorting algorithm. Bubble Sort is a simple and Pass 1 easy to implement comparison based sorting <43751> ------> <34751> algorithm. We will describe the algorithm by <34751> ------> <34571> sorting a list of n numbers in increasing order <34571> ------> <34517> of magnitude. The same process can be Pass 2 followed to sort a list of letters according to <34517> ------> <34157> some criteria. The input to the algorithm will Pass 3 be a list of n numbers in a random order and <34157> ------> <31457> the output will be a list of the same n numbers Pass 4 arranged in an increasing order of magnitude. <31457> ------> <13457> The algorithm terminates at this stage. ALGORITHM DESCRIPTION Input : List of n numbers COMPLEXITY Output : The same list of n numbers arranged The complexity of the Bubble Sort algorithm in increasing order of magnitude. is O(n*2) and so bubble sort should not be The Bubble sort algorithm works by stepping used when n is large. through the list of numbers and comparing pairs of numbers. If the pair being compared is REFERENCES in the wrong order , that is the larger of the 1. Introduction To Algorithms - Coreman two is before the smaller, the algorithm swaps 2. Wikipedia web site the position of the two numbers. The process is