Python Learning Week 5 (Solution)
Task 1 Write a program in python to implement given Graph, BFS and DFS. Output must be as given below CODE: graph = { ‘E’ : [‘A’,’B’], ‘A’ : [‘D’], ‘B’ : [‘D’], ‘D’ : [‘C’], ‘C’: [] } #EDGE-LIST def edges(graph): edge_list = [] for node in graph: for neighbour in graph[node]: edge_list.append((node, neighbour)) return edge_list #VERTEX-LIST class Vertices_list: def __init__(self,graph_dict=None): if graph_dict is None: graph_dict = [] self.graph_dict = graph_dict def get_Vertices(self): return list(self.graph_dict.keys()) G = Vertices_list(graph) #BFS […]
Read More