# CodeStepByStep

## bigoh9

Language/Type: C++ algorithm analysis big-oh

Give a tight bound of the nearest runtime complexity class for each of the following code fragments in Big-Oh notation, in terms of the variable N. In other words, write the code's growth rate as N grows. Write a simple expression that gives only a power of N using a caret `^` character for exponentiation, such as `O(N^2)` to represent O(N2) or `O(log N)` to represent O(log2 N). Do not write an exact calculation of the runtime such as O(2N3 + 4N + 14).

 ```// a) int sum = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { sum++; } for (int j = 1; j < N + 5; j++) { for (int k = 1; k < 99999; k++) { sum++; } } } cout << sum << endl;``` answer: ```// b) stack stack; set set; for (int i = 0; i < N; i++) { stack.push(N); set.insert(N); } while (!stack.empty()) { int top = stack.top(); stack.pop(); set.erase(top); } cout << "done!" << endl;``` answer: ```// c) map map; for (int i = 0; i < N; i++) { for (int j = 4; j <= 2*N + 1; j++) { map[i] = j; } } queue queue; for (int k : map) { queue.push(k); } cout << "done!" << endl;``` answer: ```// d) vector vector; unordered_set hashset; for (int i = 4; i <= N + 7; i++) { hashset.insert(i); } for (int num : hashset) { vector.push_back(num); } while (!vector.empty()) { vector.erase(vector.begin()); } cout << "done!" << endl;``` answer: