const graph = {
'A': ['B', 'C'],
'B': ['A', 'D', 'E'],
'C': ['A', 'F'],
'D': ['B'],
'E': ['B', 'F'],
'F': ['C', 'E']
};
function bfs(graph, start){
const visited = new Set();
const queue = [start];
visited.add(start);
while(queue.length > 0){
const vertex = queue.shift();
console.log(vertex);
for(const neigbor of graph[vertex]){
if(!visited.has(neigbor)){
console.log(vertex+'-'+neigbor);
visited.add(neigbor);
queue.push(neigbor);
}
}
}
}
A
A-B
A-C
B
B-D
B-E
C
C-F
D
E
F