Bubble sort -array

why we need to subtract i from j<=n-1-i?? it still working fine without subtraction explain, please

ques:- https://online.codingblocks.com/app/player/189104/content/180082/6859/lecture

video time at- 6:35

hello @dasvishal60

yeah that will work fine but it will do some redundant iterations to reduce that redundant operations we are iterating till j<=n-1-i

when i=1 that means [0…n-1] part is unsorted so our j should go till [0…n-2]
after this iteration n-1 index will get its correct value.
when i=2 that means [0…n-2] part is unsorted so our j should go till [0…n-3]
so on

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.