Design & Analysis of Algorithms Ics 2301
Design & Analysis of Algorithms Ics 2301
Design & Analysis of Algorithms Ics 2301
b) Write an algorithm for insertion sort and analyse its time complexity for the best and worst case.
(10 marks)
c) (i) Define a loop invariant. (2 marks)
(ii) Describe the loop in variant property for the insertion sort algorithm derived in question one
(b) above. (9 marks)
d) Consider the following statements in the pseudo-code below, what list of elements would be in the
Array A, Dryrun to show your answer. (5 marks)
b) Explain the concept of asymptotic notations indicating the commonly used notations and their
significance. (6 marks)
d) Differentiate between bottom up approach and top down approach in dynamic programming.
(6 marks)
Question Four
a) Explain the necessity of time and space complexity analysis of algorithm with suitable examples.
(6 marks)
b) (i) Write an algorithm for bubble sort. (6 marks)
(ii) Apply the algorithm in question b(i) above to sort the list E, X, A, M, P, L, E
(4 marks)
c) Compute the big-oh running time of the following code segment. (4 marks)
for (i = 2, I <n; i++) {
sum + 2;
}
Question Five
a) (i) What do we mean when we say that a sorting algorithm is stable (2 marks)
(ii) Is insertion sort stable? (2 marks)