Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions graph/bfs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
__author__ = 'Minsuk Heo'

vertexList = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
edgeList = [(0,1), (1,2), (1,3), (3,4), (4,5), (1,6)]
vertexList = ["0", "1", "2", "3", "4", "5", "6"]
edgeList = [(0, 1), (0, 2), (1, 0), (1, 3), (2, 0), (2, 4), \
(2, 5), (3, 1), (4,2), (4, 6), (5,2), (6,4)]
graphs = (vertexList, edgeList)

def bfs(graph, start):

vertexList, edgeList = graph
visitedList = []
queue = [start]

adjacencyList = [[] for vertex in vertexList]

# fill adjacencyList from graph
Expand All @@ -19,9 +22,8 @@ def bfs(graph, start):
current = queue.pop()
for neighbor in adjacencyList[current]:
if not neighbor in visitedList:
queue.insert(0,neighbor)
queue.insert(0, neighbor)
visitedList.append(current)
return visitedList

print(bfs(graphs, 0))


print (bfs(graphs, 0))