This project allows users to create a graph by specifying the number of nodes and edges, and then count the possible paths between two specified nodes.
- Python 3.x
- NetworkX
- Matplotlib
To install the required packages, run:
pip install networkx matplotlib- Run the script:
python graph.pyor
python3 graph.py-
Follow the prompts to input the number of nodes and edges, and then specify the edges.
-
The script will display the adjacency matrix and visualize the graph.
-
Input the start and end nodes to count the possible paths between them.
The number of Nodes: 4
The Number of links: 5
U: 1
V: 2
U: 1
V: 3
U: 1
V: 4
U: 2
V: 3
U: 3
V: 4
The Adjacent Matrix:
[0, 1, 1, 1]
[1, 0, 1, 0]
[1, 1, 0, 1]
[1, 0, 1, 0]
Start of counting: 1
End of counting: 4
Number of paths between 1 and 4: 2
- The script creates an adjacency matrix based on user input.
- It visualizes the graph using NetworkX and Matplotlib.
- It includes a function
count_pathsto count the possible paths between two nodes using recursion.
This project is licensed under the MIT License.