Question: Compute for the space complexity, total cost and identify the time complexity of the program below. #include using namespace std; int main() { int rows,
Compute for the space complexity, total cost and identify the time complexity of the program below.
#includeusing namespace std; int main() { int rows, count = 0, count1 = 0, k = 0; cout << "Enter number of rows: "; cin >> rows; for(int i = 1; i <= rows; ++i) { for(int space = 1; space <= rows-i; ++space) { cout << " "; ++count; } while(k != 2*i-1) { if (count <= rows-1) { cout << i+k << " "; ++count; } else { ++count1; cout << i+k-2*count1 << " "; } ++k; } count1 = count = k = 0; cout << endl; } return 0; }
SPACE COMPLEXITY:
TIME COMPLEXITY:
TOTAL COST:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
