Sorting with BubbleSort

Faizah Ahsan
2 min readDec 7, 2020

What is sorting?

Sorting means arranging systematically in groups; separate according to type, class, etc. We usually think of sorting as sorting numbers, ordering strings alphabetically, or think about ordering people in line or by height or by age or something.

But in interviews when an interviewer talking about sorting, it is usually about taking an array of numbers and sorting them from least to greatest. This is the type of question usually asked during an interview.

There are few types of sorting algorithms out there. But in this blog we will talk about BubbleSort. Bubble Sort is better to use when you have a small data set.

Problem:

Given an array which we need to sort it and return it.

In the picture, we have some numbers which we will sort.

Steps:

  1. From i = 0 to < array length
  2. From j = 0 to (array length -i)
  3. If the element at j is greater than j+1
  4. Swap elements at j and j+1

The purpose of the BubbleSort is to find the largest element in the array and drag it to the right hand side.

--

--

Faizah Ahsan

Junior Full-Stack Web Developer. Looking for opportunities!