Writing your own code: BFS
• With Python and NetworkX it is easy to write any graph-based algorithm
from collections import deque
def breadth_first_search(g, source):
queue = deque([(None, source)])
enqueued = set([source])
while queue:
parent, n = queue.popleft()
Dostları ilə paylaş: