Algorithm Design-1
Algorithm Design-1
f(N) = O(N2), where f(N) is defined to be the running time of the program:
2 Let A= (aij) be an m x n matrix and B=(bij) be an n x p matrix, both with real entries. For 2+2=4
computing the product matrix C = AB, use the algorithm implied by the definition of the matrix
product:
Find the worst case and average case complexity of this algorithm?
3 Given an array containing the digits 71808294, show how the order of the digits changes during 5+1=6
each step of quicksort (using the array-based quicksort choosing last element as the pivot).Show
the array after each swap. Mention the strategy used.
[7, 1, 8, 0, 8, 2, 9, 4]
[1, 0, 2, 4, 8, 8, 9, 7]
[1, 0, 2, 4, 8, 8, 9, 7]
[1, 0, 2, 4, 8, 8, 9, 7]
[0, 1, 2, 4, 7, 8, 8, 9]
[0, 1, 2, 4, 7, 8, 8, 9]
5 For the undirected, weighted graph given below, which of the following sequences of edges 4+4=8
represents a correct execution of Prim’s algorithm to construct a Minimum Spanning Tree?
Page 1 of 3
8
(i) (a, b), (d, f), (f, c), (g, i), (d, a), (g, h), (c, e), (f, h)
(ii) (c, e), (c, f), (f, d), (d, a), (a, b), (g, h), (h, f), (g, i)
(iii) (d, f), (f, c), (d, a), (a, b), (c, e), (f, h), (g, h), (g, i)
(iv) (h, g), (g, i), (h, f), (f, c), (f, d), (d, a), (a, b), (c, e)
6) 5+1+1
+1=8
Compute shortest paths between all pairs of vertices in the above graph, clearly
showing/explaining all intermediate steps.
Mention the algorithm, time complexity of the algorithm used.
Also specify the design strategy employed.
Page 3 of 3