menu_book Course Curriculum (Data Structures & Algorithms) expand_more
Complexity & Foundations
Arrays & Strings
Linked Lists
Stacks & Queues
Hashing
Trees & Heaps
Graphs
Depth-first search
Learn Depth-first search in Data Structures & Algorithms with a focused explanation, a topic-specific example, edge guidance, and a mastery check.
12 min read
•
Advanced
Advertisement
data-structures-algorithms-063.py
python
graph={"A":["B","C"],"B":["D"],"C":[],"D":[]};seen=set()
def dfs(n):
if n in seen:return
seen.add(n);print(n)
for nxt in graph[n]:dfs(nxt)
dfs("A")
What to watch
Content source & attribution
Original Syntaxis Content · Original Syntaxis Content