Why we initialize outer loop with 1 and inner loop with Zero. Please Elaborate

In Bubble Sort function , Why we initialize outer loop with 1 and inner loop with Zero. Please Elaborate

hi @menaveen06
Outer loop signifies the interation number. And using inner loop we are actually performing the swaps… We can start outer loop also from 0, then we will have to accordingly reduce the end till where it goes, and similarly make changes in inner loop…

1 Like

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.

Thanks Vaibhav for your support. I’m redeveloping my Datastructure Skill with Coding Block

1 Like

If we give for(int i=1;i <= n-1;i++){
for(int j = 0; j <= n-i-1;j++ ){

It shows the correct sorted values

But If we give for(int i=0;i <n-1;i++){
for(int j = 0; j <= n-i-1;j++ )

It shows not the desired result![Untitled|690x323]

hi @menaveen06
if u want to start outer loop from 0, the corrected code -->

I like to know, what’s problem when I initialise outer loop with 0. When we give size of the array more than 5, it creates problem