Assignments
Assignments
210
3n+100logn
4n
2logn
nlogn
4nlogn+2n
n2+10n
2n
n3
4. Given an integer number n, your task is to write two different algorithms in
pseudo-codes to calculate 2n, and evaluate the complexity of the algorithms.
5. #include<bits/stdc++.h>
6. using namespace std;
7.
8. int power_of_two(int n) {
9. return 1 << n;
10. }
11.
12. int main() {
13. int n = 5;
14. cout << "2^n = " << power_of_two(n) <<
endl;
15. return 0;
16. }
17.
#include<bits/stdc++.h>
using namespace std;
int power_of_two(int n) {
int result = 1;
for (int i = 0; i < n; i++) {
result *= 2;
}
return result;
}
int main() {
int n = 5;
cout << "2^n = " << power_of_two(n) << endl;
return 0;
}
O(n^2)
Function Matrix:
for (i = 0 ; i < n ; i++)
for (j = 0 ; j < n ; j++)
if (i == j)
A[i][j] = 1;
else
A[i][j] = 0;
O(n^2)
23. Find the order of nodes in preorder, postorder, and inorder traversals
39
70 83
53 61 72 16
24 48
cd
a b