Daa Unit-3 (Mid-1)
Daa Unit-3 (Mid-1)
Explain about
i) Principles of optimality ii) Feasible solution iii) Optimal solution.
And also differentiate how the Dynamic Programming is different from Divide
and Conquer.
Optimal Substructure: Relies on the principle of No Need for Optimal Substructure: Breaks the
optimality, where the optimal solution to a problem into independent subproblems and
problem can be constructed from optimal combines their solutions without needing to
solutions to its subproblems. store intermediate results.
Approach: Bottom-up approach, where smaller Approach: Top-down approach, where the
subproblems are solved first and combined to problem is recursively divided into smaller
solve the overall problem. subproblems.
Example: Fibonacci sequence, where Example: Merge sort, where the array is divided
overlapping subproblems are solved once and into two halves, and each half is sorted
stored for future reference. independently.
Discuss about the Algorithm for All Pairs Shortest Path problem and Apply
the Same on the following.
ABCD
A0541
B5023
C 4206
D1 360
ABCD
A0541
B5023
C 4206
D1 360
ABCD
A0541
B5023
C 4205
D1 350
ABCD
A0541
B5023
C 4205
D1 350
ABCD
A0541
B5023
C 4205
D1 350
ABCD
A0441
B4023
C 4205
D1 350
ABCD
A0441
B4023
C 4205
D1 350
Conclusion
The final matrix represents the shortest distances between all pairs of vertices.
For example, the shortest path from A to B is 4, and the shortest path from C to
D is 5.