Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

U IVERSITY OF IBADA DEPARTME T OF COMPUTER SCIE CE 2 D SEMESTER EXAMI ATIO 2010/2011 SESSIO CSC 233: PROGRAMMI G & ALGORITHMS

I STRUCTIO : ATTEMPT A G 5 QUESTIO S. TIME ALLOWED: 2 HRS

(a) Use a relevant example to explain the notion of invariant in Algorithms (4 MARKS) 1 (b) 4. Illustrate how the data E S C E I C will be arranged in ascending order using (i)Selection sort (ii)Insertion sort (8 marks) 1(c) Explain why the binary search algorithm is extremely efficient when dealing with large data sets (3 marks) 2. (a) Outline the generic form of a divide and conquer algorithm (5 marks) 2(b) Explain in one sentence each, how Linear Programming algorithms may be applied so solve problems in each of the following situations? (8 marks) (i) Politics (ii) Airline service (iii) Internet Service providers (iv) oil drilling 2c Successful electronic commerce depends on the privacy and security of personal information such as credit card numbers, passwords, and bank statements. Mention 2 core algorithms that are used in electronic commerce (2 marks) 3(a) List the following functions from lowest asymptotic order to highest asymptotic order. If any two (or more) are of the same order, indicate which : (4 marks) n, n!, 2n, nlogn, n3, n2, logn, n2 + logn 3(b) Find the order of the algorithm that will compute each of the following functions: (8 marks) (i) 2n2 + 1 (ii) 2n+1 (iii) 3n2 + (iv) logn 3c What would be the order of each of the following algorithms: (3 marks) (i) printing a list of n items to the screen, looking at each item once. (ii) taking a list of items, cutting it in half repeatedly until there's only one item left. (iii) taking a list of n items, and comparing every item to every other item. 4. (a) How many comparisons are required for a decision tree which sorts 5 numbers? Give your explanation. (4 marks) 4(b) Consider sorting n numbers stored in array A by first finding the smallest element of A and exchanging it with the element in A[1]. Then find the second smallest element of A, and exchange it with A[2]. Continue in this manner for the first n-1 elements of A. Write pseudocode for this algorithm. This algorithm is also known as selection sort. (5 marks) 4(c) A farmer wishes to ferry a goat, a cabbage and a wolf across a river but his boat and only take one at a time. The goat should not be left alone with the cabbage and the wolf should not be left alone with the goat. Using the procedure that the farmer employs to achieve his task, explain the concept of brute force search. (6 marks) 5(a) What do you understand by the term Big O notation? (2 marks)

1.

CSC 233 Exam 2010/2011 session

Page |1

5(b) Describe the following running time using an algorithm that searches for a string within an array of words in each case. (10 marks) (i) O(N) (ii) O(N2) 5(c) Mention 3 factors that characterize the precise form of a divide and conquer algorithm (3 marks) Illustrate how the insertion sort algorithm below will work on the array A = {5, 2, 4, 5, 1 3} (5 marks) INSERTION-SORT 1 for j = 2 to A.length 2 key = A[j] 3 // Insert A[j] into the sorted sequence A[i..j-1] 4 i = j-1 5 while i > 0 and A[i] > key 6 A[i+1] = A[i] 7 I = i-1 8 A[i+1] = key 6b Rewrite the INSERTION-SORT procedure above to sort into decreasing order instead of increasing order of magnitude (5 marks) 6c A rectangular chocolate bar divided into squares by horizontal and vertical lines is to be cut into individual squares by cutting along these lines, such that each cut splits one piece to two pieces. The cuts are indicated by the solid lines in the figure by the right (the figure shows a 4 x 3 chocolate bar that has been cut into five pieces). Find, with valid explanation, how many cuts are needed to completely cut the chocolate into all its pieces. ? (5 marks) 6 a.

Fig. 1: Chocolate bar problem

Best of luck! Yetunde Folajimi

CSC 233 Exam 2010/2011 session

Page |2

You might also like