Series of Exrcises 2: Tutorial & Lab Session
Series of Exrcises 2: Tutorial & Lab Session
Series of Exrcises 2: Tutorial & Lab Session
EXERCISE 1: (TUTO)
f)
Give the complexity class in Big O notation for each of int sum = 0;
the following code fragments, It is asked to do an exact for (int i = 1; i <= N; i++) {
for (int j = 1; j <= 100; j++) {
calculation such as O (2N3 + 4N + 14) before deducing sum++;}}
the answer. أحسب التعقيد الخوارزمي مع التبرير for (int k = 1; k <= 10000; k++) {
a) sum++;}
int sum = 0; cout << sum << endl;
for (int i = 1; i <= N + 2; i++) { h)
sum++; int sum = 0;
} for (int i = 0; i < N * 2; i++) {
for (int j = 1; j <= N * 2; j++) { for (int j = 0; j < 100; j++) {
sum += 5;} for (int k = 0; k < j*j*j; k++) {
cout << sum << endl; sum++;}}}
b) cout << sum << endl;
int sum = 0; i)
for (int i = 1; i <= N - 5; i++) { int sum = 0;
for (int j = 1; j <= N - 5; j += 2) { for (int i = 0; i < N * 2; i++) {
sum++;}} for (int j = 0; j < i/2; j++) {
cout << sum << endl; for (int k = 0; k < N*N; k++) {
c) sum++;}}}
int sum = N; cout << sum << endl;
for (int i = 0; i < 1000000; i++) { j)
for (int j = 1; j <= i; j++) { int count = 0;
sum += N;} for (int i = N; i > 0; i /= 2)
for (int j = 1; j <= i; j++) { for (int j = 0; j < i; j++)
sum += N;} count++;
for (int j = 1; j <= i; j++) {
sum += N;}}
cout << sum << endl; EXERCISE 2: (TUTO)
d)
The same question of the previous exercise for the
int sum = 0;
for (int i = 1; i <= N - 2; i++) { following recursive calls. نفس السؤال السابق لحاالت التراجع اآلتية
for (int j = 1; j <= i + 4; j++) { a)
sum++;} int function1(int n)
sum++;} {
if (n <= 0)
for (int i = 1; i <= 100; i++) { return 1;
sum++;} else
cout << sum << endl; return 1 + function1(n-1);}
e) b)
int sum = 0; int function2(int n)
for (int i = 1; i <= N; i++) { { if (n <= 0)
for (int j = 1; j <= N * N; j++) { return 1;
sum++; else
} return 1 + function2(n-5);}
for (int j = 1; j <= 100; j++) { c)
sum++; int function3(int n)
} { if (n <= 0)
for (int j = 1; j <= N; j++) { return 1;
sum++;} else
sum++;} return 1 + function3(n/5);}
cout << sum << endl;