Why it’s i+1 and not i-1 when we are returning the value of remaining element?
Recursion First occurence
@vanshikasharma1645, sorry for late reply we were facing some technical issues,
the function is defined as linearSearch(int*a,int i,int n,int key),
this function returns the index of first occurence of key in the range [i,n]
so what we are doing at ith index we check if ith element is equal to index or not , if equal then we return the index i, else we call linearSearch(a,i+1,n,key) which means we are now finding key in the range[i+1,n] the reason we did i+1 is because we called function in the range [i,n] if ith element is not key we are sure it had to be in the range [i+1,n]
In case of any doubt feel free to ask
Mark your doubt as RESOLVED if you got the answer
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.