Skip to main content

Command Palette

Search for a command to run...

Bubble Sort Algorithm

How does Bubble Sort Work?

Published
1 min readView as Markdown
Bubble Sort Algorithm
M
Software Engineer with 5+ years of experience designing and building clinical-grade systems, including Electronic Medical Records (EMR), medical imaging tools, and scalable backend infrastructures. I specialize in developing end-to-end healthcare solutions using Python and Django REST Framework, with a strong focus on clinical workflow automation, multilingual systems, and high-performance data handling. My work includes building modular EMR platforms, prescription engines, and hybrid search systems for accurate medical data retrieval. I have also worked on medical imaging applications, integrating Python-based tools with analysis modules to support diagnostic workflows and image-based decision-making.
  • traverse from the left and compare adjacent elements and the higher one is placed at the right side.

  • In this way, the largest element is moved to the rightmost end at first.

  • This process is then continued to find the second largest and place it and so on until the data is sorted.

function bubbleSort(array) {
  // Only change code below this line
  let j, i, temp;
  let n = array.length;
  for(i=0;i<n-1; i++){
     for(j=0; j < n-i-1; j++){
       if(array[j] > array[j+1]){
          temp = array[j];
          array[j] = array[j+1];
          array[j+1] = temp;
       }
       console.log(array[j]);
     }
  }
  return array;
  // Only change code above this line
}

Time Complexity: O(N2)
Bubble sort has a time complexity of O(N2) 
which makes it very slow for large data sets.

More from this blog

eikon

17 posts

Hello! I am Monyuy a software engineer. A day in my life consists of prepping web art, fixing front end bugs, adding API endpoint, database design and blogging.