0

I am trying to write a python program that takes input as "adjacency list (or dictionary) to represent an undirected graph", "source vertex" and "destination vertex".

The program should use Breadth First Search and output all possible paths from source to vertex within the given graph.

Since this is an assignment where I just need to find all paths between a source and goal I used networkx to get the job done, but I want to be able to write it myself using BFS.

d = {'1': ['3', '4', '5'], '3': ['1', '4'], '4':['1','3'], '5':['1']}

g = nx.Graph(d)

for path in nx.all_simple_paths(g, source='5', target='4'):
    print(path)

I have had several failed attempts and am unable to find solution elsewhere. Any help, is appreciated. have a good day! thanks!

sudiksha
  • 55
  • 1
  • 6

0 Answers0