Bubble sort algorithm, flow chart, analysis and Java program

Bubble sort

Bubble sort is a simple and common sorting algorithm. It sorts by iterating through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. This process will be continued until all the elements are being sorted i.e.; no swapping is required in the list.Bubble sort name came for this algorithm due to - like a bubble comes to the top of the water, each iteration will push one smaller element to the top of the list (if the algorithm is for ascending order).

Performance

Bubble sort is not the efficient algorithm in terms of the performance because its worst-case and average complexity both ?(n2), where n is the number of items being sorted.

Algorithm

START DECLARE n, list ACCEPT n ACCEPT n values into an array list DO swapped := false; FOR EACH i IN 0 to n-1 LOOP IF list[i] > list[i+1] THEN temp := list[i] list[i]:=list[i+1] list[i+1]:=temp END IF END LOOP WHILE swapped = trueEND