menu_book Course Curriculum (Data Structures & Algorithms) expand_more
Complexity & Foundations
Arrays & Strings
Linked Lists
Stacks & Queues
Hashing
Trees & Heaps
Graphs
Breadth-first search
Learn Breadth-first search in Data Structures & Algorithms with a focused explanation, a topic-specific example, edge guidance, and a mastery check.
12 min read
•
Advanced
data-structures-algorithms-064.py
python
from collections import deque
graph={0:[1,2],1:[3],2:[4],3:[],4:[]};q=deque([0]);seen={0}
while q:
n=q.popleft();print(n)
for v in graph[n]:
if v not in seen:seen.add(v);q.append(v)
What to watch
Content source & attribution
Original Syntaxis Content · Original Syntaxis Content