Data structure and Algorithm 3, Lecture notes of Data Structures and Algorithms

index 2013,Data structure and Algorithm,2025/2026,bedad,hulk

Typology: Lecture notes

2025/2026

Uploaded on 12/15/2025

abdul-rahman-mahmoud
abdul-rahman-mahmoud 🇩🇿

1 document

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
University of Ain Temouchent - BELHADJ Bouchaib
Faculty of Science and Technology
Department of Mathematics and Computer Science
Computer Science 2nd Year, Semester 3 ADS 3
2025/2026 1/3
Tutorial n° 1
« Algorithmic complexity »
Exercise 1
Determine the number of elementary operations in the following algorithms:
1. S 0 ;
For i from 1 to n
S++ ;
EndFor
Exercise 2
For each of the following algorithms, determine the number of operations (op) performed as a function
of n.
1. For i from 1 to n
op ;
EndFor
2. For i from 1 to n
op;
EndFor
op ;
3. For i from 1 to n
For j from 1 to m
op ;
EndFor
EndFor
4. For i from 1 to n
For j from 1 to n
For k from 1 to n
op ;
EndFor
EndFor
EndFor
5. For i from 1 to n
op; op ;
For j from 1 to n
op ;
For k from 1 to n
op ;
EndFor
EndFor
EndFor
6. For i from 1 to n
For j from i to n
op
EndFor
EndFor
2. S 0 ;
For i from 1 to n
For j from 1 to n
S++ ;
EndFor
EndFor
3. T 0 ;
While (n>0) do
T T + n ;
n -- ;
EndWhile
pf3

Partial preview of the text

Download Data structure and Algorithm 3 and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

Faculty of Science and Technology Department of Mathematics and Computer Science Computer Science – 2 nd^ Year, Semester 3 ADS 3

Tutorial n° 1

« Algorithmic complexity »

Exercise 1

Determine the number of elementary operations in the following algorithms:

1. S 0 ; For i from 1 to n S++ ; EndFor

Exercise 2

For each of the following algorithms, determine the number of operations (op) performed as a function of n.

1. For i from 1 to n op ; EndFor 2. For i from 1 to n op; EndFor op ; 3. For i from 1 to n For j from 1 to m op ; EndFor EndFor 4. For i from 1 to n For j from 1 to n For k from 1 to n op ; EndFor EndFor EndFor 5. For i from 1 to n op; op ; For j from 1 to n op ; For k from 1 to n op ; EndFor EndFor EndFor 6. For i from 1 to n For j from i to n op EndFor EndFor

2. S ← 0 ;

For i from 1 to n For j from 1 to n S++ ; EndFor EndFor

3. T ← 0 ;

While (n>0) do T T + n ; n -- ; EndWhile

Faculty of Science and Technology Department of Mathematics and Computer Science Computer Science – 2 nd^ Year, Semester 3 ADS 3

Exercise 3

Determine if the function f is in the order of g ( f = O(g) ?) in the following cases: a) f(n) = n^2 + 10n, g(n) = n^2 b) f(n) = 3n^3 +2n^2 +n+1, g(n) = n^3 c) f(n) = 2n^2 +n+1, g(n) = n^3 d) f(n) = n^2 +n, g(n) = n

Exercise 4

Give the asymptotic complexity in Landau notation (Big O) and the corresponding class for each of the following functions Ti(n): T 0 (n) = 3 n (for example T 0 ϵ O(n) : linear complexity). T 1 (n) = 6 n^3 + 10 n^2 + 5 n + 2 T 2 (n) = 3 log (n) + 4 T 3 (n) = 2n^ + 6 n^2 + 7n T 4 (n) = 7k + 2 / k : constant T 5 (n) = 4 log (n) + n T 6 (n) = 2 log (k) + k n^2

Exercise 5

a) Calculate the number of iterations of the following module and deduce its asymptotic complexity: For i from 1 to n For j from i+1 to n If (T[i] > T[j]) Then tmp T[i] ; T[i] T[j] ; T[j] tmp ; EndIf EndFor EndFor