So, I have this graph and I want to use the breadth-first search algorithm to see if there is a path from a vertex to another.
So, I implemented a function in python which returns true or false, depending on the existence of a path and it works. Well, it worked for the tests I made. What I want to know is if this is indeed a breath-first search algorithm. I haven't seen any BFS algorithm before and I only know its base idea. I heard that BFS is implemented recursively, though I implemented it iteratively and that's why I have doubts about it.So, here are both the function and the representation of my graph:
outb = {1: [2, 3],
2: [4, 5],
3: [5, 11, 12],
4: [6, 7],
5: [7],
6: [9, 10],
7: [8],
11: [3],
12: [15, 14, 13],
13: [17],
14: [17],
15: [12, 5, 8, 16],
17: [18]}
def BFS(v1, v2):
parsed = []
toParse = [v1]
current = v1
while len(toParse) > 0:
while current in parsed:
current = toParse.pop(0)
if current not in outb:
return False
if v2 in outb[current]:
return True
toParse += outb[current]
parsed.append(current)
return False
And the last questions I have is: Is BFS, by its nature, finding the shortest path from a vertex to another? I read this thing on the internet and I want to be sure.

S == parsed,Q == toParse,current == current. - Barmarcurrent not in outbdoesn't mean there is no path, and you try to dotoParse.pop(0)without considering whethertoParseactually has any elements. Also, lists are not an efficient choice for most of the data structures used. - user2357112 supports Monicain outb, because someone made the choice to omit keys fromoutbif they don't have outgoing edges. If the search reaches such a node before it reaches the destination, the search will wrongly outputFalse. - user2357112 supports Monica