I am not able to understand parteek bhaiya first aproch how that recursion is working int i =firstocc(a+1,n-1,key);
In this plz help me to understand this.
Linear search using recursion
the function firstocc() checks if the value at current index is equal to key and if it is it returns the current index else it calls itself with next index, since it first checks 0 then 1, 2, 3 and so on it will always return the first index.
Sir it means always it will return index value
And sir if it return index then in last occurrence questions it will return index as n as we don’t apply any condition before it . Then how last occurrence work
say we are at ith index the further indexes are only called if the element is not present at ith index.
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.