Assuming each arithmetic and output operation takes constant time, what is the…
PYQ IBPS SO CRP SPL-XIII (2023)
Assuming each arithmetic and output operation takes constant time, what is the overall time complexity of the following code?
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cout << "Enter the size of the 3D matrix (n x n x n): ";
cin >> n;
vector<vector<vector<int>>> matrix(
n,
vector<vector<int>>(n, vector<int>(n))
);
cout << "3D Matrix with sums at each coordinate (i, j, k):" << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
matrix[i][j][k] = i + j + k;
cout << "Value at ("
<< i << ", "
<< j << ", "
<< k << ") = "
<< matrix[i][j][k]
<< endl;
}
}
}
return 0;
}- A.
O(n)
- B.
O(n2)
- C.
O(n3)
- D.
O(n log n)
- E.
O(log n)
Attempted by 40 students.
Sign up free to check your answer
Sign up freeLoading lesson…

