Oh My Algorithm
Algorithm Guidecomplexity: O(1) 양끝 삽입/삭제

덱 (Deque)

양쪽 끝에서 모두 삽입·삭제가 가능한 이중 종단 큐입니다. 스택과 큐를 모두 흉내낼 수 있어 슬라이딩 윈도우·회문 검사·양방향 탐색에 활용됩니다.

01 Explore How It Works

Interactive Step-by-Step
Deque · 양끝 삽입·삭제
empty

덱(Deque) 시작. 양쪽 끝 모두에서 넣고 뺄 수 있는 이중 종단 큐입니다.

Logic Node1 / 8

02 Understand It Simply

For Everyone
🔑Analogy

양쪽이 뚫린 컨베이어 — 앞에서도 뒤에서도 물건을 넣고 뺄 수 있습니다.

💡In Plain Words

큐와 스택을 합친 형태로, 양쪽 끝 모두에서 넣고 뺄 수 있어 더 유연합니다.

📍Where It's Used
  • 최근 사용 목록(오래된 건 앞에서 버리고 새 건 뒤에 추가)
  • 회문 검사
  • 슬라이딩 윈도우

03 Python Implementation

A clean, readable reference implementation of the core logic of 덱 (Deque).

core_implementation.py
from collections import deque

dq = deque()
dq.append(x)        # 뒤에 추가
dq.appendleft(x)    # 앞에 추가
dq.pop()            # 뒤에서 제거
dq.popleft()        # 앞에서 제거
dq[0], dq[-1]       # 양끝 조회

04 Frequently Asked Questions

FAQ
What is 덱 (Deque)?+

양쪽 끝에서 모두 삽입·삭제가 가능한 이중 종단 큐입니다. 스택과 큐를 모두 흉내낼 수 있어 슬라이딩 윈도우·회문 검사·양방향 탐색에 활용됩니다.

What is the time complexity of 덱 (Deque)?+

The time complexity of 덱 (Deque) is O(1) 양끝 삽입/삭제. Follow the step-by-step visualization to see exactly why.

Where is 덱 (Deque) used?+

최근 사용 목록(오래된 건 앞에서 버리고 새 건 뒤에 추가), 회문 검사, 슬라이딩 윈도우.

What's a simple analogy for 덱 (Deque)?+

양쪽이 뚫린 컨베이어 — 앞에서도 뒤에서도 물건을 넣고 뺄 수 있습니다.

Guide Progress0%