I have written my version of strstr function in c. I am using a temporary array of size 26. Then is the space complexity O(1) or O(n)? This is my code :
void strcheck(char t[], int n, char p[], int m)
{
int i, j, k;
int temp[26];
for (i = 0; i < 25; ++i)
temp[i] = 0;
for (i = 0; i < n; ++i)
{
k = t[i] - 'a';
temp[k]++;
}
for (j = 0; j < m; j++)
{
k = p[j] - 'a';
if (temp[k] > 0)
temp[k]--;
else
break;
}
if (j == m)
printf("string occured\n");
else
printf("not occured\n");
}
The program is working correctly just wanna know about space complexity. Thanks
O(1)
n
(or any other variable for that matter).