{"id":48402,"date":"2025-05-07T12:44:39","date_gmt":"2025-05-07T07:14:39","guid":{"rendered":"https:\/\/www.iquanta.in\/blog\/?p=48402"},"modified":"2025-05-07T12:49:40","modified_gmt":"2025-05-07T07:19:40","slug":"bubble-sort-algorithm-with-complexity-analysis","status":"publish","type":"post","link":"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/","title":{"rendered":"Bubble Sort Algorithm with Complexity Analysis"},"content":{"rendered":"\n<p>We have completed all the basic data structures which includes Arrays, Linked List, Queues. <a href=\"https:\/\/www.iquanta.in\/blog\/what-is-stack-in-data-structure-types-and-real-world-examples\">Stacks<\/a>, <a href=\"https:\/\/www.iquanta.in\/blog\/graph-data-structure-its-types-and-representation\/\">Graphs<\/a> and<a href=\"https:\/\/www.iquanta.in\/blog\/tree-in-data-structure-its-advantages-types-and-operation\"> Trees<\/a>. To look after the complexity behind the work with these structures we need different algorithms.<\/p>\n\n\n\n<p>As algorithm is the step by step process to complete a particular task, which includes the complexity analysis that is time and space complexities. In this blog we will be covering bubble sort algorithm, covering its implementation in C and C++ programming languages, complexity analysis along with its advantages and disadvantages.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_77 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#What_is_Bubble_Sort_Algorithm\" >What is Bubble Sort Algorithm?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#How_Bubble_Sort_Works\" >How Bubble Sort Works?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#Step-by-Step_Working_of_Bubble_Sort_Algorithm\" >Step-by-Step Working of Bubble Sort Algorithm<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#Example\" >Example:<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#Implementation_of_Bubble_Sort_Algorithm_in_C\" >Implementation of Bubble Sort Algorithm in C<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#Implementation_of_Bubble_Sort_Algorithm_in_C-2\" >Implementation of Bubble Sort Algorithm in C++<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#Complexity_Analysis_of_Bubble_Sort_Algorithm\" >Complexity Analysis of Bubble Sort Algorithm<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#Advantages_and_Disadvantages_of_Bubble_Sort\" >Advantages and Disadvantages of Bubble Sort<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#Advantages_of_Bubble_Sort\" >Advantages of Bubble Sort<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#Disadvantages_of_Bubble_Sort\" >Disadvantages of Bubble Sort<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-what-is-bubble-sort-algorithm\"><span class=\"ez-toc-section\" id=\"What_is_Bubble_Sort_Algorithm\"><\/span><strong>What is Bubble Sort Algorithm?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Bubble Sort Algorithm is a simple algorithm to sort the array by comparing the adjacent elements. It is a sorting algorithm that repeatedly continue the steps of swapping the larger value with the small one.<\/p>\n\n\n\n<p>Let&#8217;s understand with the basic example of Bubble Sort Algorithm in which we are introducing an unsorted array of 5 elements                    [ 1, 7, 3, 15, 2]. In this example we have taken these 5 elements which is stored in array in an unsorted manner and need to sort this array with the bubble sort algorithm.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/chat.whatsapp.com\/B6weknl7133BQXjPva0pgB\"><img fetchpriority=\"high\" decoding=\"async\" width=\"875\" height=\"142\" src=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-30.png\" alt=\"bubble sort algorithm\" class=\"wp-image-48423\" srcset=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-30.png 875w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-30-300x49.png 300w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-30-768x125.png 768w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-30-150x24.png 150w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-30-696x113.png 696w\" sizes=\"(max-width: 875px) 100vw, 875px\" \/><\/a><\/figure><\/div>\n\n\n<p>Step 1: First we need to check the first two pair of adjacent elements 1 and 7. In this the larger element is at the end so no need to change anything. Instead of that need to check next two distinct elements. <\/p>\n\n\n\n<p>Resultant array after 1st step : [1, 7, 3, 15, 2].<\/p>\n\n\n\n<p>Step 2 :  Need to check next adjacent elements which are 7 and 3. Now in this case larger element is at start, we need to take it at the end. <\/p>\n\n\n\n<p>Resultant array after step 2 : [1,3, 7, 15, 2]<\/p>\n\n\n\n<p>Step 3: Now need to compare other two adjacent element and in that case larger element is 15 and hence no need to change.<\/p>\n\n\n\n<p>Resultant array after step 3 : [1, 3, 7, 15, 2]<\/p>\n\n\n\n<p>Step 4: It is the final check of first cycle of bubble sort algorithm to sort an array. In this we need to check next two elements 15 and 2 . Now in this again we need to take 15 to the end.<\/p>\n\n\n\n<p>Resultant array after 4th step : [1, 3, 7, 2, 15]<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"735\" height=\"813\" src=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-29.png\" alt=\"bubble sort algorithm\" class=\"wp-image-48417\" srcset=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-29.png 735w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-29-271x300.png 271w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-29-380x420.png 380w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-29-150x166.png 150w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-29-300x332.png 300w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-29-696x770.png 696w\" sizes=\"(max-width: 735px) 100vw, 735px\" \/><\/figure><\/div>\n\n\n<p>Hence we have completed our first cycle here and we will continue similar steps until and unless we are not getting our array in a sorted manner. I will not prefer to use this algorithm with complex and large datasets as it&#8217;s having high complexity.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-bubble-sort-works\"><span class=\"ez-toc-section\" id=\"How_Bubble_Sort_Works\"><\/span><strong>How Bubble Sort Works?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The bubble sort algorithm is a simple sorting technique that repeatedly compares adjacent elements in a list and swaps them if they are in the wrong order. This process is repeated until the list is sorted.<\/p>\n\n\n\n<p>Imagine the elements in an array as bubbles. The largest bubble (element) &#8220;bubbles up&#8221; to the end of the array with each full pass through the list. This continues until no more swaps are needed, which means the array is sorted.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step-by-Step_Working_of_Bubble_Sort_Algorithm\"><\/span><strong>Step-by-Step Working of Bubble Sort Algorithm<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ol>\n<li>Start at the beginning of the array.<\/li>\n\n\n\n<li>Compare the first two elements.<\/li>\n\n\n\n<li>Swap them if the first is greater than the second (for ascending order).<\/li>\n\n\n\n<li>Move to the next pair of adjacent elements and repeat the comparison and swap if necessary.<\/li>\n\n\n\n<li>Continue this process until the end of the array \u2014 this completes one pass.<\/li>\n\n\n\n<li>Repeat the entire process for the remaining unsorted part of the array.<\/li>\n\n\n\n<li>Stop when a complete pass is made without any swaps \u2014 the array is now sorted.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example\"><\/span>Example:<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Let\u2019s sort the array: [5, 2, 9, 1]<\/p>\n\n\n\n<ol>\n<li>First pass: [5, 2, 9, 1] \u2192 [2, 5, 9, 1] \u2192  [2, 5, 9, 1]  \u2192 [2, 5, 1, 9]<\/li>\n\n\n\n<li>Second pass:[2, 5, 1, 9] \u2192 [2, 5, 1, 9] \u2192 [2, 1, 5, 9]<\/li>\n\n\n\n<li>Third pass:[2, 1, 5, 9] \u2192 [1, 2, 5, 9]<\/li>\n\n\n\n<li>Fourth pass: No swaps needed. Sorting is complete.<\/li>\n<\/ol>\n\n\n\n<p>The final sorted array is [1, 2, 5, 9].<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/chat.whatsapp.com\/B6weknl7133BQXjPva0pgB\"><img decoding=\"async\" width=\"875\" height=\"142\" src=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-31.png\" alt=\"bubble sort algorithm\" class=\"wp-image-48424\" srcset=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-31.png 875w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-31-300x49.png 300w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-31-768x125.png 768w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-31-150x24.png 150w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-31-696x113.png 696w\" sizes=\"(max-width: 875px) 100vw, 875px\" \/><\/a><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-implementation-of-bubble-sort-algorithm-in-c\"><span class=\"ez-toc-section\" id=\"Implementation_of_Bubble_Sort_Algorithm_in_C\"><\/span><strong>Implementation of Bubble Sort Algorithm in C<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\r\n\r\n\/\/ Function to perform Bubble Sort\r\nvoid bubbleSort(int arr&#091;], int n) {\r\n    int temp;\r\n    int swapped;\r\n\r\n    for (int i = 0; i &lt; n - 1; i++) {\r\n        swapped = 0;  \/\/ Flag to optimize and break early if no swaps\r\n\r\n        for (int j = 0; j &lt; n - i - 1; j++) {\r\n            \/\/ Compare adjacent elements\r\n            if (arr&#091;j] &gt; arr&#091;j + 1]) {\r\n                \/\/ Swap if elements are in wrong order\r\n                temp = arr&#091;j];\r\n                arr&#091;j] = arr&#091;j + 1];\r\n                arr&#091;j + 1] = temp;\r\n                swapped = 1;\r\n            }\r\n        }\r\n\r\n        \/\/ If no two elements were swapped, the array is already sorted\r\n        if (swapped == 0)\r\n            break;\r\n    }\r\n}\r\n\r\n\/\/ Function to print the array\r\nvoid printArray(int arr&#091;], int n) {\r\n    for (int i = 0; i &lt; n; i++)\r\n        printf(\"%d \", arr&#091;i]);\r\n    printf(\"\\n\");\r\n}\r\n\r\n\/\/ Main function\r\nint main() {\r\n    int arr&#091;] = {64, 34, 25, 12, 22, 11, 90};\r\n    int n = sizeof(arr) \/ sizeof(arr&#091;0]);\r\n\r\n    printf(\"Original array:\\n\");\r\n    printArray(arr, n);\r\n\r\n    bubbleSort(arr, n);\r\n\r\n    printf(\"Sorted array:\\n\");\r\n    printArray(arr, n);\r\n\r\n    return 0;\r\n}\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-implementation-of-bubble-sort-algorithm-in-c-0\"><span class=\"ez-toc-section\" id=\"Implementation_of_Bubble_Sort_Algorithm_in_C-2\"><\/span><strong>Implementation of Bubble Sort Algorithm in C++<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\n\/\/ Function to perform Bubble Sort\r\nvoid bubbleSort(int arr&#091;], int n) {\r\n    bool swapped;\r\n\r\n    for (int i = 0; i &lt; n - 1; i++) {\r\n        swapped = false;\r\n\r\n        \/\/ Loop through the array up to the unsorted part\r\n        for (int j = 0; j &lt; n - i - 1; j++) {\r\n            \/\/ Swap if the elements are in the wrong order\r\n            if (arr&#091;j] &gt; arr&#091;j + 1]) {\r\n                swap(arr&#091;j], arr&#091;j + 1]);\r\n                swapped = true;\r\n            }\r\n        }\r\n\r\n        \/\/ If no elements were swapped, the array is already sorted\r\n        if (!swapped)\r\n            break;\r\n    }\r\n}\r\n\r\n\/\/ Function to print the array\r\nvoid printArray(int arr&#091;], int n) {\r\n    for (int i = 0; i &lt; n; i++)\r\n        cout &lt;&lt; arr&#091;i] &lt;&lt; \" \";\r\n    cout &lt;&lt; endl;\r\n}\r\n\r\n\/\/ Main function\r\nint main() {\r\n    int arr&#091;] = {64, 25, 12, 22, 11};\r\n    int n = sizeof(arr) \/ sizeof(arr&#091;0]);\r\n\r\n    cout &lt;&lt; \"Original array:\" &lt;&lt; endl;\r\n    printArray(arr, n);\r\n\r\n    bubbleSort(arr, n);\r\n\r\n    cout &lt;&lt; \"Sorted array:\" &lt;&lt; endl;\r\n    printArray(arr, n);\r\n\r\n    return 0;\r\n}\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-complexity-analysis-of-bubble-sort-algorithm\"><span class=\"ez-toc-section\" id=\"Complexity_Analysis_of_Bubble_Sort_Algorithm\"><\/span><strong>Complexity Analysis of Bubble Sort Algorithm <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Complexity Analysis of bubble sort algorithm is O(n^2). Here is a detailed below about the complexity analysis of bubble sort algorithm.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/chat.whatsapp.com\/B6weknl7133BQXjPva0pgB\"><img loading=\"lazy\" decoding=\"async\" width=\"875\" height=\"142\" src=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-32.png\" alt=\"bubble sort algorithm\" class=\"wp-image-48425\" srcset=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-32.png 875w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-32-300x49.png 300w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-32-768x125.png 768w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-32-150x24.png 150w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-32-696x113.png 696w\" sizes=\"(max-width: 875px) 100vw, 875px\" \/><\/a><\/figure><\/div>\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th><strong>Case<\/strong><\/th><th><strong>Time Complexity<\/strong><\/th><th><strong>Explanation<\/strong><\/th><\/tr><\/thead><tbody><tr><td>Best Case<\/td><td>O(n)<\/td><td>When the array is already sorted (only one pass needed with no swaps).<\/td><\/tr><tr><td>Average Case<\/td><td>O(n\u00b2)<\/td><td>On average, each element is compared with every other element.<\/td><\/tr><tr><td>Worst Case<\/td><td>O(n\u00b2)<\/td><td>When the array is sorted in reverse order (maximum number of swaps).<\/td><\/tr><tr><td>Space Complexity<\/td><td>O(1)<\/td><td>In-place sorting no additional memory required.<\/td><\/tr><tr><td>Stability<\/td><td>Yes<\/td><td>Bubble Sort is stable and it does not change the relative order of equal elements.<\/td><\/tr><tr><td>Adaptive<\/td><td>Yes <\/td><td>If optimized with a swap flag, it can adapt and exit early if sorted.<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Complexity Table for Bubble Sort Algorithm<\/figcaption><\/figure>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"455\" height=\"389\" src=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-34.png\" alt=\"complexity analysis of bubble sort algorithm\" class=\"wp-image-48428\" srcset=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-34.png 455w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-34-300x256.png 300w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-34-150x128.png 150w\" sizes=\"(max-width: 455px) 100vw, 455px\" \/><figcaption class=\"wp-element-caption\">Complexity graph of Bubble Sort<\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-advantages-and-disadvantages-of-bubble-sort\"><span class=\"ez-toc-section\" id=\"Advantages_and_Disadvantages_of_Bubble_Sort\"><\/span><strong>Advantages and Disadvantages of Bubble Sort<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If I am specifically taking about bubble sort then we will see there are some advantages are there to use this algorithm but at the same point due to complexity there are several disadvantages too.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-advantages-of-bubble-sort\"><span class=\"ez-toc-section\" id=\"Advantages_of_Bubble_Sort\"><\/span><strong>Advantages of Bubble Sort<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ol>\n<li>Bubble Sort does not require additional memory space.<\/li>\n\n\n\n<li>Easy to understand and implement.<\/li>\n\n\n\n<li>It is useful for teaching basic sorting concepts and algorithm design.<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/chat.whatsapp.com\/B6weknl7133BQXjPva0pgB\"><img loading=\"lazy\" decoding=\"async\" width=\"875\" height=\"142\" src=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-33.png\" alt=\"image whatsapp community\" class=\"wp-image-48426\" srcset=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-33.png 875w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-33-300x49.png 300w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-33-768x125.png 768w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-33-150x24.png 150w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-33-696x113.png 696w\" sizes=\"(max-width: 875px) 100vw, 875px\" \/><\/a><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-disadvantages-of-bubble-sort\"><span class=\"ez-toc-section\" id=\"Disadvantages_of_Bubble_Sort\"><\/span><strong>Disadvantages of Bubble Sort<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ol>\n<li>It performs too many unnecessary comparisons and swaps, making it inefficient for large input sizes.<\/li>\n\n\n\n<li>Due to its time complexity, it is much slower than advanced algorithms like merge sort.<\/li>\n\n\n\n<li>It is not widely used in many real world applications due to its poor performance.<\/li>\n<\/ol>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have completed all the basic data structures which includes Arrays, Linked List, Queues. Stacks, Graphs and Trees. To look after the complexity behind the work with these structures we need different algorithms. As algorithm is the step by step process to complete a particular task, which includes the complexity analysis that is time and [&hellip;]<\/p>\n","protected":false},"author":560,"featured_media":48438,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1075,1073],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.4 (Yoast SEO v21.9.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Bubble Sort Algorithm with Complexity Analysis - iQuanta<\/title>\n<meta name=\"description\" content=\"In this blog we will be covering bubble sort algorithm, covering its implementation in C and C++ programming languages and Complexity Analysis\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bubble Sort Algorithm with Complexity Analysis\" \/>\n<meta property=\"og:description\" content=\"In this blog we will be covering bubble sort algorithm, covering its implementation in C and C++ programming languages and Complexity Analysis\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/\" \/>\n<meta property=\"og:site_name\" content=\"iQuanta\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/iquanta.in\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-07T07:14:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-07T07:19:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/Your-paragraph-text-13.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1600\" \/>\n\t<meta property=\"og:image:height\" content=\"900\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Nidhi Goswami\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nidhi Goswami\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/\"},\"author\":{\"name\":\"Nidhi Goswami\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/#\/schema\/person\/ec8c8c25d0526dd86557b6fed064f7f3\"},\"headline\":\"Bubble Sort Algorithm with Complexity Analysis\",\"datePublished\":\"2025-05-07T07:14:39+00:00\",\"dateModified\":\"2025-05-07T07:19:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/\"},\"wordCount\":824,\"publisher\":{\"@id\":\"https:\/\/www.iquanta.in\/blog\/#organization\"},\"articleSection\":[\"DSA and Competitive Programming\",\"iSkills\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/\",\"url\":\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/\",\"name\":\"Bubble Sort Algorithm with Complexity Analysis - iQuanta\",\"isPartOf\":{\"@id\":\"https:\/\/www.iquanta.in\/blog\/#website\"},\"datePublished\":\"2025-05-07T07:14:39+00:00\",\"dateModified\":\"2025-05-07T07:19:40+00:00\",\"description\":\"In this blog we will be covering bubble sort algorithm, covering its implementation in C and C++ programming languages and Complexity Analysis\",\"breadcrumb\":{\"@id\":\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.iquanta.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bubble Sort Algorithm with Complexity Analysis\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/#website\",\"url\":\"https:\/\/www.iquanta.in\/blog\/\",\"name\":\"iQuanta | Cat Preparation Online\",\"description\":\"Building Learning Networks\",\"publisher\":{\"@id\":\"https:\/\/www.iquanta.in\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.iquanta.in\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/#organization\",\"name\":\"IQuanta\",\"url\":\"https:\/\/www.iquanta.in\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2018\/08\/IQuanta-1.png\",\"contentUrl\":\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2018\/08\/IQuanta-1.png\",\"width\":525,\"height\":200,\"caption\":\"IQuanta\"},\"image\":{\"@id\":\"https:\/\/www.iquanta.in\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/facebook.com\/iquanta.in\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/#\/schema\/person\/ec8c8c25d0526dd86557b6fed064f7f3\",\"name\":\"Nidhi Goswami\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/21d234d87afd924b217d26b25a3cf1ee?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/21d234d87afd924b217d26b25a3cf1ee?s=96&d=mm&r=g\",\"caption\":\"Nidhi Goswami\"},\"url\":\"https:\/\/www.iquanta.in\/blog\/author\/nidhigoswami\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Bubble Sort Algorithm with Complexity Analysis - iQuanta","description":"In this blog we will be covering bubble sort algorithm, covering its implementation in C and C++ programming languages and Complexity Analysis","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/","og_locale":"en_US","og_type":"article","og_title":"Bubble Sort Algorithm with Complexity Analysis","og_description":"In this blog we will be covering bubble sort algorithm, covering its implementation in C and C++ programming languages and Complexity Analysis","og_url":"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/","og_site_name":"iQuanta","article_publisher":"https:\/\/facebook.com\/iquanta.in","article_published_time":"2025-05-07T07:14:39+00:00","article_modified_time":"2025-05-07T07:19:40+00:00","og_image":[{"width":1600,"height":900,"url":"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/Your-paragraph-text-13.png","type":"image\/png"}],"author":"Nidhi Goswami","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Nidhi Goswami","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#article","isPartOf":{"@id":"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/"},"author":{"name":"Nidhi Goswami","@id":"https:\/\/www.iquanta.in\/blog\/#\/schema\/person\/ec8c8c25d0526dd86557b6fed064f7f3"},"headline":"Bubble Sort Algorithm with Complexity Analysis","datePublished":"2025-05-07T07:14:39+00:00","dateModified":"2025-05-07T07:19:40+00:00","mainEntityOfPage":{"@id":"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/"},"wordCount":824,"publisher":{"@id":"https:\/\/www.iquanta.in\/blog\/#organization"},"articleSection":["DSA and Competitive Programming","iSkills"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/","url":"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/","name":"Bubble Sort Algorithm with Complexity Analysis - iQuanta","isPartOf":{"@id":"https:\/\/www.iquanta.in\/blog\/#website"},"datePublished":"2025-05-07T07:14:39+00:00","dateModified":"2025-05-07T07:19:40+00:00","description":"In this blog we will be covering bubble sort algorithm, covering its implementation in C and C++ programming languages and Complexity Analysis","breadcrumb":{"@id":"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.iquanta.in\/blog\/bubble-sort-algorithm-with-complexity-analysis\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.iquanta.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Bubble Sort Algorithm with Complexity Analysis"}]},{"@type":"WebSite","@id":"https:\/\/www.iquanta.in\/blog\/#website","url":"https:\/\/www.iquanta.in\/blog\/","name":"iQuanta | Cat Preparation Online","description":"Building Learning Networks","publisher":{"@id":"https:\/\/www.iquanta.in\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.iquanta.in\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.iquanta.in\/blog\/#organization","name":"IQuanta","url":"https:\/\/www.iquanta.in\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.iquanta.in\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2018\/08\/IQuanta-1.png","contentUrl":"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2018\/08\/IQuanta-1.png","width":525,"height":200,"caption":"IQuanta"},"image":{"@id":"https:\/\/www.iquanta.in\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/facebook.com\/iquanta.in"]},{"@type":"Person","@id":"https:\/\/www.iquanta.in\/blog\/#\/schema\/person\/ec8c8c25d0526dd86557b6fed064f7f3","name":"Nidhi Goswami","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.iquanta.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/21d234d87afd924b217d26b25a3cf1ee?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/21d234d87afd924b217d26b25a3cf1ee?s=96&d=mm&r=g","caption":"Nidhi Goswami"},"url":"https:\/\/www.iquanta.in\/blog\/author\/nidhigoswami\/"}]}},"_links":{"self":[{"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/posts\/48402"}],"collection":[{"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/users\/560"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/comments?post=48402"}],"version-history":[{"count":7,"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/posts\/48402\/revisions"}],"predecessor-version":[{"id":48439,"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/posts\/48402\/revisions\/48439"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/media\/48438"}],"wp:attachment":[{"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/media?parent=48402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/categories?post=48402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/tags?post=48402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}