EXAMINATION FOR THE BACHELOR OF SCIENCE IN INFORMATION
TECHNOLOGY (3.2 & 4.2)
CSC 311 ANALYSIS AND DESIGN OF ALGORITHMS
DATE: TIME: 2 HOURS
INSTRUCTIONS TO CANDIDATES a) Answer ALL questions from section A(Compulsory)
b) Answer ANY TWO questions from section B
SECTION A: ANSWER ALL QUESTIONS Question 1 (30 Marks) (a) Define an algorithm [2 mks] (b) Use a flowchart to explain algorithm design and analysis process. [6 mks] (c) List the functions below from lowest asymptotic to the highest. [2 mks] 2n , n log n, log n, n − n3 + 7n5 . (d) Let an array A consist of the following elements. A= −15 −6 0 7 9 23 54 82 101 112 125 131 142 151 i. Using appropriate table, perform Binary search for x = 9. [4 mks] ii. Draw a binary search decision tree for A. [3 mks] (e) A computer performs 1 billion steps per second. Calculate the time required by the computer to execute an algorithm whose running time T (n) is given as.( Assume n = 4) [4 mks] i. n log2 n. ii. 2n . (f) Use recursion tree to solve the following recurrence relation equations [4 mks] T(n) = T(n − 1) + 1 (g) Explain FIVE criteria that an algorithm must satisfy. [5 mks]
SECTION B: ATTEMPT ANY TWO QUESTIONS
Question 2 (20 Marks) (a) Prove that for a polynomial f (n) = am nn + · · +a1 n + a0 , then f (n) = O(2n ). [4 mks] (b) Write control abstraction for Divide and Conquer technique. [4 mks] (c) Use the abstraction in (b) to illustrate mergesort algorithm using array A below. [4 mks] A= 310 285 179 652 351 423 861 254 450 520 (d) Use the array A to draw a decision tree of algorithm Mergesort(1:10) [3 mks] (e) Using an appropriate example, explain the graph coloring problem. [5 mks]
Question 3 (20 Marks)
(a) State two phases of testing algorithms. [2 mks] (b) Solve the following problem of Job sequencing with the deadlines specified using greedy strategy. N=4, (P1, P2, P3, P4) = (100, 10, 15, 27) (d1, d2, d3, d4) = (2, 1, 2, 1) [7 mks] (c) Explain THREE differences between Dynamic programming and divide and conquer. [6 mks] (d) The recurrence relation of mergesort algorithm T (n) is shown below. ( T (1) 2 T (n) = 2T (n/2) + n otherwise
Use substitution method to show that T (n) = O(n log n). where n = 2k , k ≥ 0. [5 mks]
Question 4 (20 Marks)
(a) Write partition subroutine as used in quicksort algorithm. [4 mks] (b) Explain how backtracking technique is applied in 4-queens problem. [6 mks] (c) Consider the multistage weighted graph shown in Figure 1. Use dynamic program- ming to calculate least cost path from S to T using i. forward approach [5 mks] ii. backward approach [5 mks]