You are on page 1of 2

CC04 ACTIVITY #7

➢ INSERT AN IMAGE OF THE BUBBLE SORT


AND EXPLAIN.

“CONVERT THE FILE INTO PDF FORMAT


BEFORE YOU SUBMIT.”

GOOD LUCK! ☺ ☺ ☺
➢ INSERT AN IMAGE OF THE BUBBLE SORT
AND EXPLAIN.

Bubble sort is a sorting algorithm that compares two adjacent elements and swaps them until
they are not in the intended order. Just like the movement of air bubbles in the water that rise up
to the surface, each element of the array moves to the end in each iteration. Therefore, it is
called a bubble sort.

Suppose we want to sort an array, let’s name it arr, with n elements in ascending order; this is
how the bubble sort algorithm will work.

1. Starts from the first index: arr[0] and compares the first and second element: arr[0] and
arr[1]
2. If arr[0] is greater than arr[1], they are swapped
3. Similarly, if arr[1] is greater than arr[2], they are swapped
4. The above process continues until the last element arr[n-1]

All four steps are repeated for each iteration. Upon completing each iteration, the largest
unsorted element is moved to the end of the array. Finally, the program ends when no elements
require swapping, giving us the array in ascending order. Now that we know the working of the
bubble sort let’s implement it in C programming using different methods.

You might also like