4 Module Daa
4 Module Daa
4 Module Daa
Notice that Fib(3) is calculated twice, and Fib(2) and Fib(1) are calculated multiple times in
this process.
Divide and Conquer:
Divide and Conquer is a technique that breaks down a problem into smaller, non-
overlapping subproblems, solves these subproblems independently, and combines their
solutions to solve the original problem. Unlike dynamic programming, it typically doesn't
store or reuse solutions to subproblems.
Example of Divide and Conquer:
The merge sort algorithm exemplifies the divide and conquer strategy. It breaks down an
array into smaller subarrays, sorts these subarrays, and then merges them back together in
a sorted manner.
Dynamic Programming:
Answer: Warshall's algorithm is used to find the transitive closure of a directed graph. The
transitive closure of a graph shows all the vertices reachable from every vertex in the graph.
Warshall's Algorithm:
for k from 1 to V: (V is the number of vertices)
for i from 1 to V:
for j from 1 to V:
tc[i][j] = tc[i][j] OR (tc[i][k] AND tc[k][j])
This algorithm works by considering each vertex as an intermediate vertex and updates the
transitive closure matrix if there exists a path between two vertices through the
intermediate vertex.
Example Application:( replace 1,2,3,4 as a,b,c,d as a graph edge)
Let's consider a directed graph given by its adjacency matrix:
5. Make use of Warshall’s Algorithm for the following given graph to compute transitive
closure
Answer:
6. Apply Floyd’s Algorithm for the following given graph to find all pair shortest path.
Answer:
8. Apply Travelling Salesperson Problem (TSP) Algorithm for the following given graph
using dynamic programming.