Added the program of Adjacency Matrix #1077
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request for PyVerse 💡
Requesting to submit a pull request to the PyVerse repository.
Issue Title
Please enter the title of the issue related to your pull request.
Adjacency Matrix
Info about the Related Issue
What's the goal of the project?
Write a program in python to create adjacency matrix of a given graph. If a graph has n vertices, we use n x n matrix to represent the graph.Let's assume the n x n matrix as adj[n][n].
if there is an edge from vertex i to j, mark adj[i][j] as 1. i.e. adj[i][j] == 1
if there is no edge from vertex i to j, mark adj[i][j] as 0. i.e. adj[i][j] == 0
I have described the aim of the project.
Name
Please mention your name.
Shuvojit Samanta
GitHub ID
Please mention your GitHub ID.
shuvojitss
Email ID
Please mention your email ID for further communication.
[email protected]
Identify Yourself
Mention in which program you are contributing (e.g., WoB, GSSOC, SSOC, SWOC).
GSSOC
Closes
Enter the issue number that will be closed through this PR.
Closes: #1068
Describe the Add-ons or Changes You've Made
Give a clear description of what you have added or modified.
Algorithm for Graph Representation using an Adjacency Matrix
Initialize the Graph
adj
with dimensions10 x 10
, initialized to 0.no_of_nodes
as input from the user.Input Neighbors and Populate the Matrix
adj[i][j] = 0
for all nodes initially.adj[i][neighbor] = 1
to establish a connection.Display the Adjacency Matrix
v1
,v2
, etc.).Main Execution
create_graph
to build the adjacency matrix based on user input.display_graph
to display the adjacency matrix in a formatted manner.Type of Change
Select the type of change:
How Has This Been Tested?
Describe how your changes have been tested.
I have tested it in all python editors and its working. I am providing a sample input output to describe it.
Sample Input:
Enter the number of nodes in G: 5
Enter the number of neighbors of 0: 2
Enter the neighbors of 0 (0-based indices): 1 2
Enter the number of neighbors of 1: 2
Enter the neighbors of 1 (0-based indices): 0 3
Enter the number of neighbors of 2: 2
Enter the neighbors of 2 (0-based indices): 0 3
Enter the number of neighbors of 3: 3
Enter the neighbors of 3 (0-based indices): 2 1 4
Enter the number of neighbors of 4: 1
Enter the neighbors of 4 (0-based indices): 3
Sample Output:
The graph is:
The adjacency matrix is:
Checklist
Please confirm the following: