Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

An example of an undirected graph and its corresponding adjacency matrix is show

ID: 3662202 • Letter: A

Question

An example of an undirected graph and its corresponding adjacency matrix is shown. An undirected graph is collection of n vertices numbered 1 to n, some of which may be connected by an edge. The corresponding adjacency matrix is an nxn matrix associated to an undirected graph. The adjacency matrix has a 1 in position (i,j) if there is an edge connecting i to j, and it has a 0 in position (i,j) if there is no edge connecting i to j. Write a function make_adj that takes two inputs, a number n ( the number of vertices in the graph) and a list of the edges in the graph, and returns as output the corresponding nxn adjacency matrix. Include comments describing how the list edges is represented; it is your choice how to represent it.

Explanation / Answer

n = input("Enter the number of vertices")
// I am taking list of edges as aan array. I will ask user to enter the edge defined. The array will always have even numbers.
//Enter q to quit
edges = zeros
adj_matrix= zeros(n)
for i from 0 to n-1 do
l=input("Enter edges")
if =strcmp(l,'q')
break
else
edges[i]=l
end_for

for j from 0 to size(edges)
if(edges[j] && edges[j+1])
   adj_matrix[j][j+1]=1
end_for

Now the adj_matix is our adjacency matrix ! :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote