

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Page 1 Data Structures and Algorithms • Exam 07
LATEST UPDATE 2026/2027 | PREMIUM ACADEMIC EDITION
Exam 07 of 40 | Unit code: DSA-07 | Questions: 6 | Total marks: 30 | Answer ALL questions
Define Big-O, Big-Omega and Big-Theta notation.
Answer:
Determine the time complexity of: for i in 1..n: for j in 1..i: print(i, j)
Answer:
The inner loop runs i times for each i, so the total is 1 + 2 + … + n = n(n + 1)/2, which is O(n^2 ).
Arrange in increasing order of growth: n!, n^2 , log n, 2n, n log n, n, 1.
Answer:
1 < log n < n < n log n < n^2 < 2n^ < n!
What is the complexity of: i = 1; while i < n: i = i * 2?
Answer:
The value of i doubles each time (1, 2, 4, 8, …), so the loop ends after about log2 n iterations. Complexity: O(log n).
Using linear search as an example, explain best-case, worst-case and average-case analysis.
Answer:
Page 2 Data Structures and Algorithms • Exam 07
Solve T(n) = 2T(n/2) + n using the Master theorem.
Answer:
Here a = 2, b = 2 and f(n) = n. Compute nlogb^ a^ = nlog^2 2 = n. Since f(n) = Θ(nlogb^ a), case 2 applies and T(n) = Θ(n log n).
Study answers prepared for revision purposes. Always cross-check against your lecturer’s notes and prescribed textbook.