

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
index 2013,Data structure and Algorithm,2025/2026,bedad,hulk
Typology: Lecture notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Faculty of Science and Technology Department of Mathematics and Computer Science Computer Science – 2 nd^ Year, Semester 3 ADS 3
Determine the number of elementary operations in the following algorithms:
1. S ← 0 ; For i from 1 to n S++ ; EndFor
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
For i from 1 to n For j from 1 to n S++ ; EndFor EndFor
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
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
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
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