Algorithm Analysis and Big-O Notation – Data
Structures and Algorithms: Exam-Ready
Questions and Answers
LATEST UPDATE 2026/2027 | PREMIUM ACADEMIC EDITION
Exam 07 of 40 | Unit code: DSA-07 | Questions: 6 | Total marks: 30 | Answer ALL questions
Question 1: [5 marks]
Define Big-O, Big-Omega and Big-Theta notation.
Answer:
• f(n) = O(g(n)) if there are constants c > 0 and n0 such that f(n) ≤ c·g(n) for all n ≥ n0 (an upper
bound).
• f(n) = Ω(g(n)) if f(n) ≥ c·g(n) for all n ≥ n0 (a lower bound).
• f(n) = Θ(g(n)) if f(n) is both O(g(n)) and Ω(g(n)) (a tight bound).
Question 2: [5 marks]
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(n2).
Question 3: [4 marks]
2 n
Arrange in increasing order of growth: n!, n , log n, 2 , n log n, n, 1.
Answer:
1 < log n < n < n log n < n2 < 2n < n!
Question 4: [5 marks]
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).
Question 5: [5 marks]
Using linear search as an example, explain best-case, worst-case and average-case analysis.
Answer:
• Best case: the target is the first element, 1 comparison, O(1).
• Worst case: the target is last or absent, n comparisons, O(n).
• Average case: if the target is equally likely at any position, about (n + 1)/2 comparisons, which
is O(n).
Page 1 Data Structures and Algorithms • Exam 07
Structures and Algorithms: Exam-Ready
Questions and Answers
LATEST UPDATE 2026/2027 | PREMIUM ACADEMIC EDITION
Exam 07 of 40 | Unit code: DSA-07 | Questions: 6 | Total marks: 30 | Answer ALL questions
Question 1: [5 marks]
Define Big-O, Big-Omega and Big-Theta notation.
Answer:
• f(n) = O(g(n)) if there are constants c > 0 and n0 such that f(n) ≤ c·g(n) for all n ≥ n0 (an upper
bound).
• f(n) = Ω(g(n)) if f(n) ≥ c·g(n) for all n ≥ n0 (a lower bound).
• f(n) = Θ(g(n)) if f(n) is both O(g(n)) and Ω(g(n)) (a tight bound).
Question 2: [5 marks]
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(n2).
Question 3: [4 marks]
2 n
Arrange in increasing order of growth: n!, n , log n, 2 , n log n, n, 1.
Answer:
1 < log n < n < n log n < n2 < 2n < n!
Question 4: [5 marks]
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).
Question 5: [5 marks]
Using linear search as an example, explain best-case, worst-case and average-case analysis.
Answer:
• Best case: the target is the first element, 1 comparison, O(1).
• Worst case: the target is last or absent, n comparisons, O(n).
• Average case: if the target is equally likely at any position, about (n + 1)/2 comparisons, which
is O(n).
Page 1 Data Structures and Algorithms • Exam 07