Bachelor Level / Third Year / Fifth Semester / Science
B.Sc in Computer Science and Information Technology (CSC325)
(Design and Analysis of Algorithms)
Full Marks: 60
Pass Marks: 24
Time: 3 Hours
Candidates are required to give their answers in their own words as for as practicable.
The figures in the margin indicate full marks.
Section A
Long Answers Questions
Attempt any TWO questions.
[2*10=20]
1.
Differentiate between dynamic programming and memorization. Compute the shortest path between every pairs in the following graphs using Floyd Warshall algorithm.
[10]
Part A: Difference between Dynamic Programming and Memoization
Aspect
Dynamic Programming (DP)
Memoization
Approach
Bottom-up approach
Top-down approach
Direction
Solves smaller subproblems first, builds up to larger ones
Starts from the main problem, breaks down recursively
Table Filling
Fills the entire table iteratively
Fills table entries only when needed (on demand)
Recursion
No recursion; uses iteration (loops)
Uses recursion with caching
Efficiency
May solve subproblems that are not needed
Solves only required subproblems
Space
Uses a table/array (iterative)
Uses a table/array + recursion stack
Control
Programmer controls the order of computation
Order determined by recursive calls
Overhead
No function call overhead
Has recursive function call overhead
Part B: Floyd-Warshall Algorithm — Shortest Path Between Every Pair
Edges from the graph:
A → B = 4
B → A = 1
B → C = 2
A → C = 7
C → A = 6
Initial Distance Matrix ($D^0$):
Using nodes: A, B, C (indexed as 1, 2, 3)
D0=01640∞720
Floyd-Warshall Formula:
Dk[i][j]=min(Dk−1[i][j],Dk−1[i][k]+Dk−1[k][j])
Iteration k = 1 (Intermediate vertex: A)
For each pair (i, j), check if going through A is shorter:
Conclusion: The Floyd-Warshall algorithm computes all-pairs shortest paths in O(n3) time using dynamic programming by systematically considering each vertex as an intermediate node.
2.
What is the worst case of quick sort and how does randomize quick sort handle this problem? Sort the data {−2,4,−3,6,12,10,11,13,9} using quick sort.[10]
3.
Does greedy algorithm guarantee optimal solution? Solve the Fractional knapsack problem to find maximum loot from given information.