a
r
R
A
F
F
G
and 30 more contributors
```#!/usr/bin/python

""" Author: OMKAR PATHAK """
from __future__ import annotations

from queue import Queue

class Graph:
def __init__(self) -> None:
self.vertices: dict[int, list[int]] = {}

def print_graph(self) -> None:
"""
prints adjacency list representation of graaph
>>> g = Graph()
>>> g.print_graph()
>>> g.print_graph()
0  :  1
"""
for i in self.vertices:
print(i, " : ", " -> ".join([str(j) for j in self.vertices[i]]))

def add_edge(self, from_vertex: int, to_vertex: int) -> None:
"""
adding the edge between two vertices
>>> g = Graph()
>>> g.print_graph()
>>> g.print_graph()
0  :  1
"""
if from_vertex in self.vertices:
self.vertices[from_vertex].append(to_vertex)
else:
self.vertices[from_vertex] = [to_vertex]

def bfs(self, start_vertex: int) -> set[int]:
"""
>>> g = Graph()
>>> sorted(g.bfs(2))
[0, 1, 2, 3]
"""
# initialize set for storing already visited vertices
visited = set()

# create a first in first out queue to store all the vertices for BFS
queue: Queue = Queue()

# mark the source node as visited and enqueue it
queue.put(start_vertex)

while not queue.empty():
vertex = queue.get()

# loop through all adjacent vertex and enqueue it if not yet visited
return visited

if __name__ == "__main__":
from doctest import testmod

testmod(verbose=True)

g = Graph()