Bubble Sort Algorithm

The example in the video took the array as 5,4,3,2,1 which meant 5 iterations . However the external loop began from itr=1 instead of 0. Why?

Hello @ritkumar that is just handling the number of passes if you have noticed then we must have ended are loop itr<=n-1.
either you will run for 0 to itr<n-1 or 1 to itr<=n-1.

But we have N numbers in total. Running from 0 to <N-1 implies N-2 iterations and 1 to <=N-1 implies N-1 iterations. However in the video he said that we need N-1 iterations for N-1 elements. This means we need N iterations for N elements.

let suppose we have N as 5:
then from 0 to < N-1:
we have 0,1,2,3.
whereas for 1 to <=N-1:
1,2,3,4
see we will try for the same number of times i,e 4.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.