Oh My Algorithm
Algorithm Guidecomplexity: O(1) push/pop

스택 (Stack)

마지막에 넣은 것을 가장 먼저 꺼내는 후입선출(LIFO) 구조입니다. 한쪽 끝(top)에서만 삽입·삭제가 일어나며, 함수 호출 스택·실행 취소·괄호 검사·DFS의 뼈대가 됩니다.

01 Explore How It Works

Interactive Step-by-Step
Stack · LIFO
empty

스택 시작. 한쪽 끝(top)에서만 넣고 빼는 후입선출(LIFO) 구조입니다.

Logic Node1 / 9

02 Understand It Simply

For Everyone
🔑Analogy

식당의 접시 더미. 새 접시는 맨 위에 쌓고, 꺼낼 때도 맨 위부터 집습니다.

💡In Plain Words

한쪽 끝(top)에서만 넣고 뺍니다.

가장 마지막에 넣은 것이 가장 먼저 나와요(후입선출, LIFO).

📍Where It's Used
  • 실행 취소(Ctrl+Z)
  • 브라우저 뒤로 가기
  • 괄호 짝 검사

03 Python Implementation

A clean, readable reference implementation of the core logic of 스택 (Stack).

core_implementation.py
class Stack:
    def __init__(self):
        self.items = []

    def push(self, x):
        self.items.append(x)

    def pop(self):
        if not self.items:
            raise IndexError("stack is empty")
        return self.items.pop()

    def peek(self):
        return self.items[-1] if self.items else None

    def is_empty(self):
        return len(self.items) == 0

04 Frequently Asked Questions

FAQ
What is 스택 (Stack)?+

마지막에 넣은 것을 가장 먼저 꺼내는 후입선출(LIFO) 구조입니다. 한쪽 끝(top)에서만 삽입·삭제가 일어나며, 함수 호출 스택·실행 취소·괄호 검사·DFS의 뼈대가 됩니다.

What is the time complexity of 스택 (Stack)?+

The time complexity of 스택 (Stack) is O(1) push/pop. Follow the step-by-step visualization to see exactly why.

Where is 스택 (Stack) used?+

실행 취소(Ctrl+Z), 브라우저 뒤로 가기, 괄호 짝 검사.

What's a simple analogy for 스택 (Stack)?+

식당의 접시 더미. 새 접시는 맨 위에 쌓고, 꺼낼 때도 맨 위부터 집습니다.

Guide Progress0%