#include <iostream>
using namespace std;
int main()
{
int a[100][100]={10};
cout<<a[0][0];
return 0;
}
what is the time complexity of above program? is it O(1) or O(100^2)??
O(N).O(k) == O(1) (for constant k, k > 0).As your array have fixed size, the complexity of the program is O(1).
if you change your program to something like:
#include <iostream>
#include <vector>
int main()
{
int size;
std::cin >> size;
std::vector<int> a(size);
// ..
}
There, the initialization of a is O(N).
O(100^2)is the same asO(1).Nin it. It will always run the same thing. So,O(1).