# CodeStepByStep

## bigoh3

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) unordered_set set1; for (int i = 0; i < N; i++) { set1.insert(i); } set set2; for (int n : set1) { set2.insert(n); } cout << "done!" << endl;``` answer: ```// b) vector list; for (int i = 0; i < N; i++) { list.insert(list.begin(), i*i); } set set; for (int k : list) { set.insert(k); } cout << "done!" << endl;``` answer: ```// c) vector list1; for (int i = 0; i < N; i += 2) { list1.push_back(i); } vector list2; for (int i = 0; i < N; i++) { list2.insert(list2.begin(), list1[0]); list1.erase(list1.begin()); } cout << "done!" << endl;``` answer: ```// d) int sum = 0; for (int i = 0; i < N * 2; i++) { for (int j = 0; j < 100; j++) { for (int k = 0; k < j*j*j; k++) { sum++; } } } cout << sum << endl;``` answer: ```// e) int sum = 0; for (int i = 0; i < N * 2; i++) { for (int j = 0; j < i/2; j++) { for (int k = 0; k < N*N; k++) { sum++; } } } cout << sum << endl;``` answer: