This is an algo. programmed for displaying a letter pyramid if the buildPyramids() method is passed argument str, i.e. "12345":
1
121
12321
1234321
123454321
Code:
void buildPyramids(string str) {
size_t len = str.length();
size_t i, j, k, m;
for(m=0; m<len; m++) {
for(i=len-m-1; i > 0; i--) {
cout << " ";
}
for(j=0; j<=m; j++) {
cout << str[j];
}
for(k=1; k<j; k++) {
cout << str[j-k-1];
}
cout << endl;
}
}
What's the correct way to calculate the space and time complexity for the same?
Could you also guide me to some resources for a deeper understanding of the same?