Oh My Algorithm
Algorithm Guidecomplexity: O(n)

트리 순회 (Tree Traversal)

트리의 모든 노드를 한 번씩 방문하는 방법입니다. 방문 시점에 따라 전위(루트 먼저)·중위(왼쪽→루트→오른쪽, BST에서 정렬 순)·후위(루트 마지막)·레벨 순회로 나뉩니다.

01 Explore How It Works

Interactive Step-by-Step
Inorder Traversal
50307020406080

중위 순회(inorder)를 시작합니다. 왼쪽 서브트리 → 루트 → 오른쪽 순서로 방문하며, BST에서는 정렬된 순서로 출력됩니다.

Logic Node1 / 9

02 Understand It Simply

For Everyone
🔑Analogy

가계도를 정해진 순서로 빠짐없이 한 명씩 방문하는 것과 같습니다.

💡In Plain Words

트리의 모든 노드를 한 번씩 들르는 방법입니다.

루트를 언제 방문하느냐에 따라 전위·중위·후위로 나뉘고, BST를 중위로 돌면 정렬된 순서가 나와요.

📍Where It's Used
  • 폴더 전체 출력
  • 수식 계산(파스 트리)
  • 트리 직렬화

03 Python Implementation

A clean, readable reference implementation of the core logic of 트리 순회 (Tree Traversal).

core_implementation.py
def inorder(node):
    if not node:
        return
    inorder(node.left)
    visit(node)          # 왼 → 루트 → 오른
    inorder(node.right)

def preorder(node):
    if not node:
        return
    visit(node)          # 루트 먼저
    preorder(node.left)
    preorder(node.right)

def postorder(node):
    if not node:
        return
    postorder(node.left)
    postorder(node.right)
    visit(node)          # 루트 마지막

04 Frequently Asked Questions

FAQ
What is 트리 순회 (Tree Traversal)?+

트리의 모든 노드를 한 번씩 방문하는 방법입니다. 방문 시점에 따라 전위(루트 먼저)·중위(왼쪽→루트→오른쪽, BST에서 정렬 순)·후위(루트 마지막)·레벨 순회로 나뉩니다.

What is the time complexity of 트리 순회 (Tree Traversal)?+

The time complexity of 트리 순회 (Tree Traversal) is O(n). Follow the step-by-step visualization to see exactly why.

Where is 트리 순회 (Tree Traversal) used?+

폴더 전체 출력, 수식 계산(파스 트리), 트리 직렬화.

What's a simple analogy for 트리 순회 (Tree Traversal)?+

가계도를 정해진 순서로 빠짐없이 한 명씩 방문하는 것과 같습니다.

Guide Progress0%