# BUBBLE SORT ASCENDING & DESCENDING ORDER | SHOUT CODERS

#### TIME COMPLEXITY OF BUBBLE SORT >

Bubble sort has a worst-case and average complexity of О(n2), where n is the number of items being sorted. When the list is already sorted (best-case), the complexity of bubble sort is only O(n).

.

#### OTHER NAME OF BUBBLE SORT >

Sinking Sort: Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order.

.

## PROCEDURE >

procedure bubbleSort(A : list of sortable items)
n := length(A)
repeat
swapped := false
for i := 1 to n-1 inclusive do
/* if this pair is out of order / if A[i-1] > A[i] then / swap them and remember something changed */
swap(A[i-1], A[i])
swapped := true
end if
end for
until not swapped
end procedure

.

## ASCENDING ORDER

#### ALGORITHM >

Steps:

1. Start
2. First get array list with integers and named by a[]
3. Then perform a for iteration range upto length(array)-1 by i
4. Inside that loop get a nested for loop with length(array)-2 pointed by j
5. Then check the value of the jth value with the j+1th value.
6. If the j is bigger than j+1 then swap between them.
7. If iteration performed successfully then print the array a[].
8. Stop the program.

.

PYTHON PROGRAM >

#### INPUT/OUTPUT:

Sorted Array: [0, 1, 2, 3, 4, 5, 6, 8]

.

## DESCENDING ORDER :

ALGORITHM >

Steps

1. Start
2. First get array list with integers and named by a[]
3. Then perform a for iteration range upto length(array)-1 by i
4. Inside that loop get a nested for loop with length(array)-2 pointed by j
5. Then check the value of the jth value with the j+1th value.
6. If the j is lesser than j+1 then swap between them.
7. If iteration performed successfully then print the array a[].
8. Stop the program.

.

PROGRAM >

#### C PROGRAM >

INPUT/OUTPUT:

Sorted Array: [8, 6, 5, 4, 3, 2, 1, 0]

.

STATEMENT > A class contains 50 students who acquired marks in 10 subjects write a program to display top
10 students roll numbers and marks in sorted order by using bubble sorting technique.

PROGRAM:

.

INPUT/OUTPUT:

.

This is a quick review about Bubble sorting algorithm. If you want to get the results in JAVA program then put a comment mentioning that.

.