I only ask this question because my instructor hardly taught us about Big O notation or how to find time/step complexities within code.
Give the step complexity in Big O natation of the following code snippet:
int Bar(std::vector<int> x, std::vector<int> y) {
int answer = 0;
// Assume x.size() == y.size()
if (x.size() != y.size()) {
throw std::runtime_error(“x and y size mismatch”);
}
for (int i = 0; i < x.size(); i++) {
for (int j = 0; j < y.size(); j++) {
answer += x.at(i) * y.at(j);
}
}
return answer;
}
If anyone can explain Big O notation and how to approach this problem, it would be greatly appreciated.