← 返回 meta 的题目列表Basic BFS Implementation
类型:online_judge
meta
Given a graph represented as an adjacency list, implement a program to perform breadth-first search (BFS) on that graph.
Input
A graph represented as a dictionary where keys are nodes and values are lists of adjacent nodes.
A starting node (string type).
Output
A list of nodes visited in BFS order.
Test Case
graph = {
"A": ["B", "C"],
"B": ["D", "E"],
"C": ["F"],
"D": [],
"E": ["F"],
"F": []
}
start_node = "A"
output = ["A", "B", "C", "D", "E", "F"]
Example
Input
{'A': ['B', 'C'], 'B': ['D'], 'C': ['E'], 'D': [], 'E': []}
A