You are on page 1of 7

BUBBLE SORT

SLIDESMANIA

ALGORITHM
Group 6
Lesler John Gantalao

Inna Maldia Isnaji

Fatima Vianca Musa

Erico Manuel Chiong

Hadzramar Jaafar
SLIDESMANIA
➔ Bubble 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. The pass through the list
is repeated until the list is sorted.

➔ The algorithm gets its name because smaller elements "bubble" to the top of the list, while
larger elements "sink" to the bottom. While Bubble Sort is easy to understand and
implement, it is not very efficient, especially for large datasets. Its average and worst-case
time complexity are both O(n^2), where n is the number of elements in the list. There are
more efficient sorting algorithms, such as Quick Sort or Merge Sort, that are commonly
used in practice for larger datasets.
SLIDESMANIA
1. Start at the beginning of the list.
2. Compare the first two elements. If the first element is larger than the second,
swap them.
3. Move to the next pair of elements (the second and third elements) and
repeat the comparison and swap if necessary.
4. Continue this process, moving one element forward each time, until you
reach the end of the list.
5. At this point, the largest element is guaranteed to be at the end of the list.
6. Repeat the process for the remaining elements in the list (excluding the last
one, as it is already in its correct position).
7. Continue these steps until the entire list is sorted.
SLIDESMANIA
SLIDESMANIA
Pseudocode
Time complexity
for i from 1 to N
O(n²)
for j from 0 to N – 1
if a[j] > a[j+1]
swap (a[j], a[j+1])
SLIDESMANIA
Done, Easy!
SLIDESMANIA

You might also like