<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ bubble - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ bubble - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Wed, 17 Jun 2026 20:48:29 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/bubble/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Bubble Sort Algorithm - Most Asked Questions About Bubble Sort ]]>
                </title>
                <description>
                    <![CDATA[ Bubble sort is a simple sorting algorithm that repeatedly loops through a list, compares adjacent elements, and swaps them if they are in the wrong order. The bubble sort algorithm is not the most efficient sorting algorithm when it comes to time com... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/most-asked-questions-about-bubble-sort/</link>
                <guid isPermaLink="false">66d45fe8d1ffc3d3eb89de12</guid>
                
                    <category>
                        <![CDATA[ algorithms ]]>
                    </category>
                
                    <category>
                        <![CDATA[ bubble ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Joel Olawanle ]]>
                </dc:creator>
                <pubDate>Wed, 05 Apr 2023 21:40:48 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/04/cover-template--6-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Bubble sort is a simple sorting algorithm that repeatedly loops through a list, compares adjacent elements, and swaps them if they are in the wrong order.</p>
<p>The bubble sort algorithm is not the most efficient sorting algorithm when it comes to time complexity. But it is still often used as a starting point for learning and understanding the basic principles of sorting algorithms.</p>
<p>In this article, you will explore the most commonly asked questions about the bubble sort algorithm, including its time and space complexity, best-case and worst-case runtime, implementation in JavaScript, and more.</p>
<h2 id="heading-what-is-bubble-sort-algorithm">What is Bubble Sort Algorithm?</h2>
<p>Bubble sorting is a way of sorting a list of things, like numbers or words, into a specific order. It works by looking at pairs of adjacent items in the list and swapping them if they are in the wrong order.</p>
<p>For example, if you have a list of [3, 1, 4, 2], bubble sort would compare 3 and 1, seeing that they are in the wrong order, it swaps them to get [1, 3, 4, 2]. It then compares 3 and 4, seeing that they are in the correct order, it moves on to the next pair.</p>
<p>Bubble sort continues to compare adjacent pairs and swap them if necessary until the list is completely sorted. As the algorithm progresses, smaller items "bubble" to the top of the list. This is why it's called bubble sort.</p>
<p>While bubble sort is a simple and easy-to-understand algorithm, it's not the most efficient. In fact, it has a worst-case time complexity of O(n^2), which means that it's not a good choice for sorting very large lists.</p>
<p>But it's still useful for teaching and learning about sorting algorithms and their basic principles.</p>
<h2 id="heading-implementation-of-bubble-sort-algorithm-with-javascript">Implementation of Bubble Sort Algorithm With JavaScript</h2>
<p>Here's an example implementation of the bubble sort algorithm in JavaScript:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> bubbleSort = <span class="hljs-function">(<span class="hljs-params">arr</span>) =&gt;</span> {
  <span class="hljs-keyword">let</span> swapped;

  <span class="hljs-keyword">do</span> {
    swapped = <span class="hljs-literal">false</span>;
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; arr.length - <span class="hljs-number">1</span>; i++) {
      <span class="hljs-keyword">if</span> (arr[i] &gt; arr[i + <span class="hljs-number">1</span>]) {
        [myArray[i], myArray[i + <span class="hljs-number">1</span>]] = [myArray[i + <span class="hljs-number">1</span>], myArray[i]];
        swapped = <span class="hljs-literal">true</span>;
      }
    }
  } <span class="hljs-keyword">while</span> (swapped);

  <span class="hljs-keyword">return</span> arr;
};

<span class="hljs-keyword">let</span> myArray = [<span class="hljs-number">12</span>, <span class="hljs-number">10</span>, <span class="hljs-number">3</span>, <span class="hljs-number">7</span>, <span class="hljs-number">4</span>];
<span class="hljs-built_in">console</span>.log(bubbleSort(myArray)); <span class="hljs-comment">// returns [3, 4, 7, 10, 12]</span>
</code></pre>
<p>In this implementation, you define a function that takes an array as its input. The function uses two nested loops to iterate over the array and compares adjacent elements.</p>
<p>You can read more on <a target="_blank" href="https://www.freecodecamp.org/news/how-to-implement-bubble-sort-algorithm-with-javascript/">how to write the bubble sort algorithm in this detailed article</a>.</p>
<h2 id="heading-most-asked-questions-about-bubble-sort-algorithm">Most Asked Questions About Bubble Sort Algorithm</h2>
<p>Let’s now explore some of the most common questions you would ask about the bubble sort algorithm to give you clarity.</p>
<h3 id="heading-1-what-is-the-best-case-runtime-complexity-of-standard-bubble-sort">1. What is the best-case runtime complexity of standard bubble sort?</h3>
<p>The best-case runtime complexity of standard bubble sort is O(n) when the input array is already sorted, and no element swap is needed.</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> myArray = [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">7</span>, <span class="hljs-number">10</span>, <span class="hljs-number">12</span>];
<span class="hljs-built_in">console</span>.log(bubbleSort(myArray)); <span class="hljs-comment">// returns [3, 4, 7, 10, 12]</span>
</code></pre>
<h3 id="heading-2-what-is-the-time-and-space-complexity-of-bubble-sort">2. What is the time and space complexity of bubble sort?</h3>
<p>The time complexity of bubble sort is O(n^2), where n is the number of elements in the array. The space complexity of bubble sort is O(1) because it uses only a constant amount of extra memory.</p>
<h3 id="heading-3-what-type-of-algorithm-is-bubble-sort">3. What type of algorithm is bubble sort?</h3>
<p>Bubble sort is a simple sorting algorithm that repeatedly loops through a list, compares adjacent elements, and swaps them if they are in the wrong order.</p>
<h3 id="heading-4-what-is-the-best-case-time-complexity-of-bubble-sort">4. What is the best-case time complexity of bubble sort?</h3>
<p>The best-case time complexity of bubble sort is O(n), where n is the number of elements in the array. This occurs when the input array is already sorted, and no element swap is needed.</p>
<h3 id="heading-5-what-is-the-average-case-complexity-of-bubble-sort">5. What is the average case complexity of bubble sort?</h3>
<p>The average case complexity of bubble sort is O(n^2), where n is the number of elements in the array. This occurs when the input array is unsorted, and multiple elements have to be swapped.</p>
<h3 id="heading-6-what-is-the-worst-time-complexity-of-bubble-sort">6. What is the worst time complexity of bubble sort?</h3>
<p>The worst time complexity of bubble sort is O(n^2), where n is the number of elements in the array. This occurs when the input array is reverse sorted, and every element has to be swapped.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>In this article, we've covered several frequently asked questions about bubble sort, including its time and space complexity, best and worst-case runtime, and how to implement it in JavaScript.</p>
<p>Hopefully, this article has given you a better understanding of bubble sort and its limitations. Remember that while bubble sort is a good starting point for learning about sorting algorithms, more efficient algorithms are available for sorting larger datasets.</p>
<p>Have fun coding!</p>
<p>You can access over 200 of my articles by <a target="_blank" href="https://joelolawanle.com/contents">visiting my website</a>. You can also use the search field to see if I've written a specific article.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How I did NOT code a collaborative writing app ]]>
                </title>
                <description>
                    <![CDATA[ By Eric Burel Twaikura, haikus but funnier As easy as ABC: some stranger on the Internet starts a 120 characters story, some stranger on the Internet finishes it. And that makes a Twaiku (tweet + haiku). Twaikus can be funny, serious, artistic, it’s ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-i-did-not-code-a-collaborative-writing-app/</link>
                <guid isPermaLink="false">66d45e3f4a7504b7409c3382</guid>
                
                    <category>
                        <![CDATA[ bubble ]]>
                    </category>
                
                    <category>
                        <![CDATA[ code ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Entrepreneurship ]]>
                    </category>
                
                    <category>
                        <![CDATA[ lean startup ]]>
                    </category>
                
                    <category>
                        <![CDATA[ web ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 18 Feb 2020 17:19:33 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/02/code-free-1200-2.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Eric Burel</p>
<h2 id="heading-twaikura-haikus-but-funnier">Twaikura, haikus but funnier</h2>
<p>As easy as ABC: some stranger on the Internet starts a 120 characters story, some stranger on the Internet finishes it. And that makes a Twaiku (tweet + haiku). Twaikus can be funny, serious, artistic, it’s up to you. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/02/logo_256.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/02/twaiku.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>So, as a developer, implementing something like that shouldn't be hard, right? Yes, but no. Here is the story of how it took me multiple years to create Twaikura and how you could do the same in a matter of hours.</p>
<h2 id="heading-back-to-twentyparts-and-why-it-never-came-to-existence">Back to TwentyParts and why it never came to existence</h2>
<p>TwentyParts was my first “entrepreneurial concept” back in 2015. As you may guess, the idea is to write a story in 20 parts, with each part written by a different author. </p>
<p>I was a CS student at the time and it took me 2 months to release a first draft. The result was disastrous. I didn’t even know about the concept of a “framework”, picture the code. The concept was too complex, the interface unusable.</p>
<p>I did not give up. A few months later, in 2016, I came up with a simplified version of TwentyParts, HiKoo.  I limited the length of a story to 3 tweets. And instead of rushing to development, I created mocks using a marvelous tool named MarvelApp.</p>
<p>Now I had a great UI and all, but no working code. One more app that never came to existence.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/02/hikoo.png" alt="Image" width="600" height="400" loading="lazy">
<em>Looks good, doesn't work</em></p>
<p>Fast forward to now. I’ve graduated. I’ve built my consulting company, LBKE. I’ve developed complex SaaS platforms for multiple clients. And I've kept this question running in my head:</p>
<blockquote>
<p>What prevents me from recreating TwentyParts, now I am fast and skilled and over-confident?</p>
</blockquote>
<p>After all, it would only take a full work week nowadays. Yet there’s a problem: I am not a student anymore. With one spare hour here and there, a “full work week“ can span over a few months. Too slow.</p>
<h2 id="heading-how-to-code-fast-dont">How to code fast: don’t.</h2>
<p>I’ve explored thoroughly the realms of fast web development. You may have read my previous articles on freeCodeCamp about <a target="_blank" href="https://www.freecodecamp.org/news/how-i-built-an-app-with-vulcan-js-in-four-days-6368814077b1/">Vulcan, a framework based on Meteor that makes me very productive.</a></p>
<p>Those researches all lead me to the same conclusion: the best code is the code you don’t write. </p>
<p>There are a lot of ways NOT to write code, even for a developer. Scaffolding, declarative programming, using snippets, or using an ORM are all methods to circumvent writing code. Using open source is another great example. Some may even think that developers are a bit lazy – but aren't they?</p>
<p>Yet minimal skills in web development are still necessary. That means careful thinking, lots of doc reading, debugging and so on. In the end, the time needed to create a fully functional app can only be reduced this much.</p>
<p>You know what? Using a massive framework to speed up developments feels like cheating sometimes. What if I did not have those skills? What if I was not a developer? I would have no other choice than embracing the “no-code way”. And that’s what I’ve done.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/02/code-free-1200.png" alt="Image" width="600" height="400" loading="lazy">
<em>Relax, Code will be on vacation for the remainder of this article</em></p>
<h2 id="heading-sparkling-innovations-for-web-non-developers">Sparkling innovations for web non-developers</h2>
<p>No-code solutions have been pretty bad in the past. Limited, difficult to extend, proprietary, expensive, the list is long. But some recent tools are starting to be worthy enough.</p>
<p>I will focus specifically on Bubble. Its plugin system coupled with its data management features makes it the most complete solution on the market currently. Here are a few key features and how I used them to build Twaikura.</p>
<h3 id="heading-the-ui-editor">The UI editor</h3>
<p>Bubble proposes a WYSIWYG editor (What You See Is What You Get) to create the app user interface. You put your blocks of content wherever you want, and configure their content.</p>
<p>It’s grid-based so you can have pixel perfect alignment. It handles responsiveness. So you should be able to create designs as complex as you wish.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/02/ui-bubble.png" alt="Image" width="600" height="400" loading="lazy">
<em>Building Twaikura's interface using the WYSIWYG editor.</em></p>
<p>But I’ll be honest, I am not the hugest fan. More precisely, I am not very good with it. It’s very different both from writing HTML/CSS and from using web-based design tools like Figma, so there is a learning curve.</p>
<p>I ended up sticking myself to an old school Windows 98-ish style. With a little bit of imagination you could even believe it has some “V a p o r w a v e” aesthetic.</p>
<h3 id="heading-thinking-in-workflows">Thinking in workflows</h3>
<p>The most impressive feature of Bubble to me is its “Workflows”. It lets you describe complex process in a visual language. It can mix data management (validating and storing a Twaiku, sending an email) and user experience (resetting a form, refreshing the page) transparently. You don’t need to mentally split the workflow between frontend and backend as you would do in a traditional web app.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/02/workflows.png" alt="Image" width="600" height="400" loading="lazy">
<em>Twaiku creation workflow</em></p>
<p>This example workflow is triggered when the user wants to submit the second part of a Twaiku. It will create a "Twaiku End" in the database, link it with a "Twaiku Begin", and reset the form. I could also display a success message, send a mail to a moderator and so on. Visualizing the full workflow in a single timeline is very intuitive.</p>
<h3 id="heading-complete-data-management">Complete data management</h3>
<p>Bubbles comes with a relational database and complete filtering features. That means you can easily create both forms and list of data. For example, the “Read latest Twaikus” block will load all valid Twaikus.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/02/twaikus-list.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Plugins can help secure your content. For example, there is a ReCaptcha plugin to add CAPTCHAs to your form in a matter of minutes. This is important as security is usually left behind in the prototyping steps. Malevolent bots and hackers don't care that you are a "lean startup-er", and they won't miss an opportunity to spam or hack your website.</p>
<h2 id="heading-a-few-hours-of-work-for-an-app-that-works">A few hours of work for an app that works</h2>
<p>I won’t describe all features of Bubble, because it has a lot more. The conclusion is that it's been powerful enough to write an app like Twaikura. Instead of writing tons of crappy code that will end up in a dumpster, instead of creating a visual prototype as lively as Frankenstein’s Creature, I just created something that works.</p>
<p>Is my website great? Honestly, not yet. Does it do the job? Hell yes. I had fun creating it, it cost me no more than a few hours, and I am able to test the concept in the most direct possible way. The longest part was writing this article.</p>
<p>I especially recommend no-code tools for people who want to learn web development. Taking a lot of time to produce simple features can feel frustrating at first. Using a no-code tool alongside traditional programming is a way to keep having fun. It's instructive too, because, even if you don't write code, you still have to think like a developer: designing conditional workflows, structuring a database, validating forms... That's a win-win.</p>
<p>I won't become a no-code evangelist, but Bubble is a great addition to my tool belt. And it could be great addition to yours too!</p>
<p>Thanks for the read. If you liked this article, come try a Bubble app by creating your first Twaiku on <a target="_blank" href="http://twaikura.com">twaikura.com</a>!</p>
<p><a href="https://twitter.com/lbke_fr">
<img src="https://www.freecodecamp.org/news/content/images/2019/10/Medium-follow-2019.png" alt="LBKE banner twitter" width="600" height="400" loading="lazy">
</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Bubble Sort Explained ]]>
                </title>
                <description>
                    <![CDATA[ Just like the way bubbles rise from the bottom of a glass, bubble sort is a simple algorithm that sorts a list, allowing either lower or higher values to bubble up to the top. The algorithm traverses a list and compares adjacent values, swapping them... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/bubble-sort/</link>
                <guid isPermaLink="false">66c346508ced2460cf9e9b5d</guid>
                
                    <category>
                        <![CDATA[ algorithms ]]>
                    </category>
                
                    <category>
                        <![CDATA[ bubble ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 25 Jan 2020 17:24:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9d8f740569d1a4ca3864.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Just like the way bubbles rise from the bottom of a glass, <strong>bubble sort</strong> is a simple algorithm that sorts a list, allowing either lower or higher values to bubble up to the top. The algorithm traverses a list and compares adjacent values, swapping them if they are not in the correct order.</p>
<p>With a worst-case complexity of O(n^2), bubble sort is very slow compared to other sorting algorithms like quicksort. The upside is that it is one of the easiest sorting algorithms to understand and code from scratch. </p>
<h3 id="heading-example"><strong>Example:</strong></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> arr = [<span class="hljs-number">4</span>, <span class="hljs-number">2</span>, <span class="hljs-number">6</span>, <span class="hljs-number">3</span>, <span class="hljs-number">9</span>];
<span class="hljs-keyword">let</span> sorted = <span class="hljs-literal">false</span>

<span class="hljs-keyword">while</span>(!sorted) {
  sorted = <span class="hljs-literal">true</span>
  <span class="hljs-keyword">for</span>(<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt; arr.length; i++) {
    <span class="hljs-keyword">if</span>(arr[i] &lt; arr[i - <span class="hljs-number">1</span>]) {
      <span class="hljs-keyword">let</span> temp = arr[i];
      arr[i] = arr[i - <span class="hljs-number">1</span>];
      arr[i - <span class="hljs-number">1</span>] = temp;
      sorted = <span class="hljs-literal">false</span>;
    }
  }
}
</code></pre>
<h3 id="heading-first-pass-through-the-list">First pass through the list:</h3>
<ul>
<li>Starting with <code>[4, 2, 6, 3, 9]</code>, the algorithm compares the first two elements in the array, 4 and 2. It swaps them because 2 &lt; 4: <code>[2, 4, 6, 3, 9]</code></li>
<li>It compares the next two values, 4 and 6. As 4 &lt; 6, these are already in order, and the algorithm moves on: <code>[2, 4, 6, 3, 9]</code></li>
<li>The next two values are also swapped because 3 &lt; 6: <code>[2, 4, 3, 6, 9]</code></li>
<li>The last two values, 6 and 9, are already in order, so the algorithm does not swap them.</li>
</ul>
<h3 id="heading-second-pass-through-the-list">Second pass through the list:</h3>
<ul>
<li>2 &lt; 4, so there is no need to swap positions: <code>[2, 4, 3, 6, 9]</code></li>
<li>The algorithm swaps the next two values because 3 &lt; 4: <code>[2, 3, 4, 6, 9]</code></li>
<li>No swap as 4 &lt; 6: <code>[2, 3, 4, 6, 9]</code></li>
<li>Again, 6 &lt; 9, so no swap occurs: <code>[2, 3, 4, 6, 9]</code></li>
</ul>
<p>The list is already sorted, but the bubble sort algorithm doesn't realize this. Rather, it needs to complete an entire pass through the list without swapping any values to know the list is sorted.</p>
<h4 id="heading-third-pass-through-the-list"><strong>Third pass through the list:</strong></h4>
<ul>
<li><code>[2, 4, 3, 6, 9]</code> =&gt; <code>[2, 4, 3, 6, 9]</code></li>
<li><code>[2, 4, 3, 6, 9]</code> =&gt; <code>[2, 4, 3, 6, 9]</code></li>
<li><code>[2, 4, 3, 6, 9]</code> =&gt; <code>[2, 4, 3, 6, 9]</code></li>
<li><code>[2, 4, 3, 6, 9]</code> =&gt; <code>[2, 4, 3, 6, 9]</code></li>
</ul>
<p>Clearly bubble sort is far from the most efficient sorting algorithm. Still, it's simple to wrap your head around and implement yourself. </p>
<p>Now go pour yourself a cold, bubbly beverage – you deserve it.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
