Python Code class Graph: def __init__(self, graph_repr=None): if graph_repr is None: self.vertList = {} else:self.vertList = graph_repr
Fantastic news! We've Found the answer you've been seeking!
Question:
Python Code
class Graph:
def __init__(self, graph_repr=None):
if graph_repr is None:
self.vertList = {}
else:self.vertList = graph_repr
def addVertex(self,key):
if key not in self.vertList:
self.vertList[key] = []
return self.vertList
def addEdge(self,frm,to,cost=1):
if frm not in self.vertList:
self.addVertex(frm)
if to not in self.vertList:
self.addVertex(to)
self.vertList[frm].append((to, cost))
return self.vertList
def bfs(self, start):
# Your code starts here
def dfs(self, start):
# Your code starts here
### EXTRA CREDIT, uncomment method definition if submitting extra credit
#def dijkstra(self,start):
# Your code starts here
Related Book For
Posted Date: