I've just started learning time and space complexity and I'm having trouble in calculating it for this program.
void f(int n){
int a[4] = {1, 1, 1, 1};
for(int k = 0; k < n; k++){
a[k % 4] *=3;
}
int** ptr = (int **)malloc(a[0]*sizeof(int*));
for (int j = 0; j < a[0]; j++) {
*(ptr+j) = (int*)malloc(j*sizeof(int));
for(int k = 0; k < j; k++){
printf("*");
}
}
}
I've tried to use the methods that I learned but im not sure how to use them correctly.
Can somebody explain me how to find the complexity of this example?
Thanks in advance for any help!