int *getArray(int arr[],int key,int n,int i,int temp[])
{
if(i==n)
return temp;
if(key==arr[i])
temp[i]=1;
return getArray(arr,key,n,++i,temp);
}
can anyone explain me the time and space complexity for the above code
int *getArray(int arr[],int key,int n,int i,int temp[])
{
if(i==n)
return temp;
if(key==arr[i])
temp[i]=1;
return getArray(arr,key,n,++i,temp);
}
can anyone explain me the time and space complexity for the above code
@dare_devil_007,
From each index i you are recursively calling (i+1), thus recurrence f(i)=f(i+1) + O©, thus solving this, we get, f(0)=O(n), and also only 1D arrays are used, so space O(n).