Cat1 scs3313
Cat1 scs3313
Question 1
(a) (2 marks) In analyzing the efficiency of an algorithm, explain the two aspects typically
considered.
(b) (2 marks) Give a definition of the big-Oh notation. Illustrate your answer with a diagram.
(c) Consider the problem of determining the minimum value in an array A[1..n].
i) (3 marks) Write an iterative algorithm to solve the problem and prove its correctness.
ii) (3 marks) Write a recursive algorithm to solve the problem, comparing its efficiency
with that of the algorithm in part i) above
Question 2
(a) (4 marks) Solve the following recurrence equations using the Master Method
i) T (n) = 4T (n/2) + n2 log n
ii) T (n) = 8T (n/2) + n log n
(b) (3 marks) Using an example, explain exhaustive search problem solving technique.
(c) (3 marks) Determine the time complexity of following algorithm:
newAlgorithm (n)
i←1
while i < n do
print i
i←i∗2
for j = 1 to i do
print j
1
Question 3
(a) (3 marks) Describe the Divide-and-Conquer algorithm design technique.
(b) Binary search is a classical algorithm. Given an array A[1..n] sorted in ascending order,
binary search can find whether an element key is in the array A. Informally, the algorithm
works as follows:
When length of A is at least 3, compare key against the middle element in A, if key
is larger then search in the right half of A, if key is smaller then search in the left
half of A.
i) (3 marks) Develop a pseudocode for the algorithm
ii) (4 marks) Analyze the running time of the binary search algorithm
Master Theorem
Given the recurrence T (n) = aT (n/b) + f (n).
Case 1: If f (n) = O(nlogb (a)−ϵ ) for some constant ϵ > 0, then T (n) = Θ(nlogb (a) ).
Case 2: If f (n) = Θ(nlogb (a) ), then T (n) = Θ(nlogb (a) log n).
Case 3: If f (n) = Ω(nlogb (a)+ϵ ) for some constant ϵ > 0, and if af (n/b) ≤ cf (n) for some constant
c < 1 and all sufficiently large n, then T (n) = Θ(f (n)).