Bubble Sort
Bubble Sort
1. Introduction
Bubble Sort is one of the simplest sorting algorithms in computer science. It is a comparison-based
algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if
they are in the wrong order. The process is repeated until the list is sorted.
2. How It Works
Bubble Sort works by iterating through a list multiple times. During each pass:
• If the current element is greater than the next (for ascending order), they are swapped.
• After each pass, the largest unsorted element "bubbles up" to its correct position.
3. Algorithm (Pseudocode)
plaintext
CopyEdit
5. Example
• Pass 1: [3, 5, 4, 2, 8]
• Pass 2: [3, 4, 2, 5, 8]
• Pass 3: [3, 2, 4, 5, 8]
• Pass 4: [2, 3, 4, 5, 8]
6. Advantages
7. Disadvantages
8. Applications