# CodeStepByStep

## bigoh6

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 = 1; i <= N; i++) { int k = 4000; for (int j = 1; j <= k; j++) { sum++; } } cout << sum << endl;``` answer: ```// b) int sum = 0; for (int i = 1; i <= N; i++) { sum += 2; } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N * N; j++) { sum++; } } cout << sum << endl;``` answer: ```// c) stack stack; for (int i = 1; i <= N; i++) { stack.push(i); } set set; while (!stack.empty()) { int k = stack.top(); stack.pop(); set.insert(k); } cout << "done!" << endl;``` answer: ```// d) unordered_map map1; for (int i = 1; i <= N; i++) { map1[i] = i; } map map2; for (int i = 1; i <= N; i++) { int k = map1[i]; map2[k] = k; map2[n + k] = n + k; } cout << "done!" << endl;``` answer: ```// e) vector v; for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { v.insert(v.begin(), i); } v.clear(); } while (!v.empty()) { v.erase(v.begin()); } cout << "done!" << endl;``` answer: