why is the isSorted function having arguments a+1, n-1
Array sort using recursion
Let’s assume the name of array is a and size of the array is n. Also, a is the address of the first element in the array. After checking whether first 2 elements are sorted we pass in the array a+1, where a+1 is the address of the second element in the array. Now we have to check that the next 2 elements are sorted or not. Since we pass a+1 the size of the array is also reduced by a factor of 1, so we the pass the size of the remaining array, which n-1 in this case.
Hope this helps.
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.