Bubble Sort

πŸ“˜ Data Structure and Algorithm πŸ‘ 117 views πŸ“… Nov 05, 2025
⏱ Estimated reading time: 1 min

Bubble Sort Algorithm

Bubble Sort is a simple sorting algorithm that repeatedly swaps adjacent elements if they are in the wrong order.

Algorithm Steps

  1. Compare each pair of adjacent elements.
  2. Swap them if they are in the wrong order.
  3. Repeat until no swaps are needed.

Example (C++)

void bubbleSort(int arr[], int n) {
    for (int i = 0; i < n-1; i++)
        for (int j = 0; j < n-i-1; j++)
            if (arr[j] > arr[j+1])
                swap(arr[j], arr[j+1]);
}

Time Complexity

  • Best: O(n)
  • Average/Worst: O(nΒ²)

Advantages

  • Easy to understand and implement.

Disadvantages

  • Inefficient for large datasets.

Conclusion

Bubble sort is mainly used for educational purposes and small datasets due to its simplicity.


πŸ”’ Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes

πŸ€– AI Quizer Assistant

πŸ“ Quiz
πŸ“š Categories
πŸ† Leaderboard
πŸ“Š My Score
❓ Help
πŸ‘‹ Hi! I'm your AI quiz assistant for Quizer.in!

I can help you with:
β€’ πŸ“ Finding quizzes
β€’ πŸ† Checking leaderboard
β€’ πŸ“Š Your performance stats

Type 'help' to get started! πŸš€
AI is thinking...