Question: Given the python code below, find the output of the print _ graph function for the following graph: # implementation of an undirected graph using
Given the python code below, find the output of the "printgraph" function for the following graph:
# implementation of an undirected graph using Adjacency Matrix, with weighted or unweighted edges
# its definitely work
class Vertex:
def initself n:
self.name n
class Graph:
vertices
edges
edgeindices
def addvertexself vertex:
if isinstancevertex Vertex and vertex.name not in self.vertices:
self.verticesvertexname vertex
for row in self.edges:
row.append
self.edges.appendlenselfedges
self.edgeindicesvertexname lenselfedgeindices
return True
else:
return False
def addedgeself u v weight:
if u in self.vertices and v in self.vertices:
self.edgesselfedgeindicesuselfedgeindicesv weight
self.edgesselfedgeindicesvselfedgeindicesu weight
return True
else:
return False
def printgraphself:
for v i in sortedselfedgeindices.items:
printv end
for j in rangelenselfedges:
printselfedgesij end
print
g Graph
# printstrlengvertices
a VertexA
gaddvertexa
gaddvertexVertexB
for i in rangeordA ordK:
gaddvertexVertexchri
edges ABAEBFCGDEDHEHFGFIFJGJHI
for edge in edges:
gaddedgeedge: edge:
gprintgraphGraph
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
