Team Members
Enrollment No. | Name | GithubId |
---|---|---|
IIB2019007 | Aditya Raj | Adityahulk |
IIB2019008 | Shyam Tayal | shyamTayal |
IIB2019009 | Abhijeet Sonkar | Abhijeet-sonkar |
Group No-"22"
Faculty Name-"Dr. Rahul Kala"
Mentor Name- "Md. Meraz"
Given a directed graph, find out if a vertex v is reachable from another vertex u for all vertex pairs (u, v) in the given graph. Here reachable mean that there is a path from vertex u to v. The reach-ability matrix is called transitive closure of a graph.
First Step is to Download/clone the repository
git clone https://github.com/shyamTayal/daa_assign_6
Change directory to the solution folder
cd daa_assign_6/Solution/
g++ closure_dfs.cpp -o dfs
./dfs
Testcase - 1
Enter the number of node : 4
Enter the number of edges : 5
0 1
0 2
1 2
2 0
2 3
****************** Reachability matrix ********************
1 1 1 1
1 1 1 1
1 1 1 1
0 0 0 1
***********************************************************
Enter the number of queries to check if v can reach u : 3
Enter the pair (v,u) to check if node v can reach node u : 2 1
Yes, 2 can reach 1
Enter the pair (v,u) to check if node v can reach node u : 3 0
No, 3 cannot reach 0
Enter the pair (v,u) to check if node v can reach node u : 1 3
Yes, 1 can reach 3
Change Directory to Testing Directory
cd daa_assign_6/testing/
g++ testcase_gen.cpp -o inp
./inp
Above commands will create 1 testing file :
- input_testcase.txt
Above testing file contains graph input for 100 testcases with with value of No. of nodes ranging from 20 to 220 and No. of edges ranging from 10 to 2010
Testing files have already been added so above step can be skipped. To be run in Testing Directory
g++ test_flloyd -o flloyd
./floyyd
g++ test_dfs -o dfs
./floyyd
- Both Above commands create two files one containing the reachability matrix generated by the input graph and other containing the Time complexity calculation data.
-
Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. The algorithm starts at the root node (selecting some arbitrary node as the root node in the case of a graph) and explores as far as possible along each branch before backtracking.
-
The Floyd Warshall Algorithm is for solving the All Pairs Shortest Path problem. The problem is to find shortest distances between every pair of vertices in a given edge weighted directed Graph.
Both algorithms have space complexity O(N2)
Since for the purpose of storing the graph elements (nodes and edges) and reachability matrix in form of a 2D - array
https://en.wikipedia.org/wiki/Floyd\%E2\%80\%93Warshall\_algorithm
https://www.geeksforgeeks.org/depth-first-search-or-dfs-for-a-graph/