Oh My Algorithm
Algorithm Guidecomplexity: O(V+E)

깊이 우선 탐색 (DFS)

Stack(LIFO)을 사용해 한 경로를 최대한 깊게 파고든 뒤 막히면 되돌아오는(backtrack) 그래프 탐색 알고리즘입니다. 메모리 사용량이 적고(O(h)) 사이클 탐지·위상 정렬·백트래킹 기반 문제 해결의 핵심이 됩니다.

01 Explore How It Works

Interactive Step-by-Step
Depth-First Search
ABCDEFGH

DFS 시작. 스택(LIFO)으로 한 경로를 최대한 깊게 파고든 뒤, 막히면 되돌아와 다음 경로를 탐색합니다. 목표는 H.

Logic Node1 / 7

02 Understand It Simply

For Everyone
🔑Analogy

미로에서 한 길을 끝까지 파고들고 막히면 되돌아오는 것.

💡In Plain Words

스택으로 한 경로를 최대한 깊게 탐색하고, 막히면 되돌아갑니다(backtrack).

메모리가 적게 들어요.

📍Where It's Used
  • 사이클 탐지
  • 위상 정렬
  • 백트래킹 문제

03 Python Implementation

A clean, readable reference implementation of the core logic of 깊이 우선 탐색 (DFS).

core_implementation.py
def dfs(graph, start, target):
    stack = [start]
    visited = set()
    parent = {start: None}
    while stack:
        current = stack.pop()
        if current in visited:
            continue
        if current == target:
            return reconstruct(parent, target)
        visited.add(current)
        for nb in graph[current]:
            if nb not in visited:
                parent[nb] = current
                stack.append(nb)
    return None

04 Frequently Asked Questions

FAQ
What is 깊이 우선 탐색 (DFS)?+

Stack(LIFO)을 사용해 한 경로를 최대한 깊게 파고든 뒤 막히면 되돌아오는(backtrack) 그래프 탐색 알고리즘입니다. 메모리 사용량이 적고(O(h)) 사이클 탐지·위상 정렬·백트래킹 기반 문제 해결의 핵심이 됩니다.

What is the time complexity of 깊이 우선 탐색 (DFS)?+

The time complexity of 깊이 우선 탐색 (DFS) is O(V+E). Follow the step-by-step visualization to see exactly why.

Where is 깊이 우선 탐색 (DFS) used?+

사이클 탐지, 위상 정렬, 백트래킹 문제.

What's a simple analogy for 깊이 우선 탐색 (DFS)?+

미로에서 한 길을 끝까지 파고들고 막히면 되돌아오는 것.

Guide Progress0%