Search This Blog

Sunday, July 5, 2020

Shortest Path Using Breadth First Search (BFS)

Shortest Path Using Breadth First Search (BFS)


Here , To find the shortest path using BFS first we have to know that the graph should always be unweighted graph .
If you know about the BFS algorithm then to find shortest path we have to add only one thing that is a dictionary named "dist" which records the distance of every node from given node As shown in below code.




Code :

No comments:

Post a Comment

Alien Dictionary

code:   from collections import defaultdict class Solution:     def __init__(self):         self.graph=defaultdict(list)                  ...