Hi everyone, let's do this question.
You are given an array of integers.
Write a function that will take this array as input and return the sorted array using bubble sort.
So this question is a standard question.
It's about bubble sort.
Now bubble sort is an algorithm where we will keep comparing values a particular value and the next
value.
For example, let's say that the given array is this one.
Let's say it's uh this one okay.
So what we'll do is we'll keep comparing a particular element and the next one.
Now if the order is not correct, that is if it's not in ascending order we will swap.
Otherwise we will move forward.
So at this point the pointer would be over here.
And we'll check this value.
And the next value.
Now there is no problem.
It's in the correct order.
So we will move this pointer to this one.
And we'll check this and the next value.
So over here we can see that the order is not correct.
So we will swap them.
So this will become 213 and then five.
And we will move the pointer.
So over here the pointer was at index one.
Right.
So we will move the pointer to index two.
And we'll check these two.
Now it's in order.
So we don't do anything.
Now we keep doing this is this is called one pass.
So we have done one pass.
And we'll do uh many passes until the given array of integers is sorted.
So that's the question.
Now let's go ahead and look at a few test cases to understand this in a better manner.
Now let's say the input is 1324.
Then the output has to be 123, four.
It's just sorted.
Now what if the input is a single integer?
If the array has just one integer, we just give that particular integer as output.
Right?
And if the input integer is already sorted, then again we just give the that particular array as output.
Alright, now let's go ahead and see how we can implement this.
Let's discuss the logic of the bubble sort.
And after that we will go ahead and code it together.