Selection sort problem

sir, i watch video 5 time but i do not understand why we use first loop til

for(i=0; i<=n-2;) like why it is n-2; condition gone;

and in second loop also j goes to j<n;

could you clarify that thing like condition for both loops .

hi @manishayadav1360_c0939b9a17f994ff
so we run the outer loop a total of n-1 times (o to <= n-2)… its so bcoz we don’t need to run it n times, as in nth loop last element left would be already in its correct position…
we run inner loop till j < n bcoz we need to compare the element with all other elements present in array…

@manishayadav1360_c0939b9a17f994ff
is there anything else??

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.