0% found this document useful (0 votes)
4 views

Bubble Sort _ Arrays

Uploaded by

sonichirag1301
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Bubble Sort _ Arrays

Uploaded by

sonichirag1301
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Bubble Sort

Bubble Sort is one of the simplest sorting algorithms. It works by repeatedly swapping adjacent elements
if they are in the wrong order. This process continues until the entire list is sorted. Here's a breakdown of
how Bubble Sort works:

Algorithm

1. Start with the first element of the list.


2. Compare the current element with the next element.
3. If the current element is greater than the next element, swap them.
4. Move to the next element and repeat steps 2–3 for the rest of the list.
5. Repeat steps 1–4 for all elements, reducing the range of comparison each time (because the
largest element "bubbles up" to its correct position in each iteration).
6. Stop when no swaps are needed in a full pass, indicating the list is sorted.

Bubble Sort Explanation with an Example

Bubble Sort is like repeatedly walking through a list of numbers, comparing pairs of adjacent elements,
and swapping them if they're out of order. Each pass ensures the largest unsorted element "bubbles up" to
its correct position.

You might also like