0% found this document useful (0 votes)
6 views2 pages

Bubble Sort

Bubble Sort is a simple comparison-based sorting algorithm that repeatedly compares and swaps adjacent elements until the list is sorted. It has a time complexity of O(n) in the best case (with optimization) and O(n²) in average and worst cases, while its space complexity is O(1). Although easy to implement and useful for small datasets, it is inefficient for larger lists and not suitable for real-world applications.

Uploaded by

Subhadip Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Bubble Sort

Bubble Sort is a simple comparison-based sorting algorithm that repeatedly compares and swaps adjacent elements until the list is sorted. It has a time complexity of O(n) in the best case (with optimization) and O(n²) in average and worst cases, while its space complexity is O(1). Although easy to implement and useful for small datasets, it is inefficient for larger lists and not suitable for real-world applications.

Uploaded by

Subhadip Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Bubble Sort – Report

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:

• Adjacent elements are compared.

• 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

for i from 0 to n-1:

for j from 0 to n-i-2:

if array[j] > array[j+1]:

swap array[j] and array[j+1]

4. Time and Space Complexity

Case Time Complexity

Best Case O(n) (if optimized with a swapped flag)

Average Case O(n²)

Worst Case O(n²)

• Space Complexity: O(1) – in-place sorting.

5. Example

For the list: [5, 3, 8, 4, 2]

• 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

• Simple to implement and understand.

• No extra space required (in-place).

• Useful for small datasets or as an educational tool.

7. Disadvantages

• Very inefficient on large lists.

• Not suitable for real-world use cases with large data.

8. Applications

• Teaching and learning sorting concepts.

• Small datasets where performance is not critical.

You might also like