{{#items}}

{{text}}

{{/items}} {{ctaText}}

{{#items}} {{/items}}

showing results for - "bfs in python 3"

Luce

12 Jan 2020

```
1graph = {
2 'A' : ['B','C'],
3 'B' : ['D', 'E'],
4 'C' : ['F'],
5 'D' : [],
6 'E' : ['F'],
7 'F' : []
8}
9
10visited = [] # List to keep track of visited nodes.
11queue = [] #Initialize a queue
12
13def bfs(visited, graph, node):
14 visited.append(node)
15 queue.append(node)
16
17 while queue:
18 s = queue.pop(0)
19 print (s, end = " ")
20
21 for neighbour in graph[s]:
22 if neighbour not in visited:
23 visited.append(neighbour)
24 queue.append(neighbour)
25
26# Driver Code
27bfs(visited, graph, 'A')
```

similar questions

how to print first thing in python functionspython list all but firstfirst n lis tpythondfs and bfs in pythondfs and bfs inn pythonfirst program of pythonhow to write your first python programbfs pythonbreadth first traversal python programpython breadth first searchpython depth first searchqueries leading to this page

bfs algorithm pythonbfs in pythonbfs python implementationbfs pythonbfs program in pythonbfs algorithm in pythonbft pythonbfs implementation in pythoncode for bfs in pythonpython bfs implementationimplement bfs algorithm using pythonbfs on pythonbfs iterative pythoncode of bfs in pythonbfs code in pythonbfs in the pythonbfs code in python as a functionbfs code pythonbfs python examplepython bfshow to implement bfs in pythonpython code for bfs algorithmbfs in python 3bfs python treimplement bfs in pythonbfs in matrix pythonbfs implementation pythonbfs function pythonpython bfs examplebfs algorithm python codebfs algorithm python implementationimplementing bfs in pythonbfs python algorithmbfs tree pythonbfs en pythonbfs python codebfs using pythonbfs python programbfs python explainedpython bfs codebfs code using function in pythonhow to use bfs in pythonbfs in python 3 your answer for

you will get a confirmation link on this - you will have to click that for successful submission of your answer. we require this to keep the website free of spam, bots and unhelpful content

please ensure to add code which is syntactically corrent and executes properly

ask question on maxinterview

you will get a confirmation link on this - you will have to click that for successful submission of your question. we require this to keep the website free of spam, bots and unhelpful content

please be clear, to the point and respectful