학습 자료

What is the difference between a stack and a queue?

이 질문은 자료구조의 기본적인 이해와 개념 설명 능력을 평가하는 질문입니다.

단순히 정의만 말하는 것이 아니라, 동작 방식(LIFO vs FIFO), 사용 예시, 시간 복잡도 등을 함께 설명하면 더욱 좋습니다.


Answer 1: Basic conceptual difference

English

A stack is a data structure that follows the Last In, First Out (LIFO) principle — the last element added is the first one to be removed. Think of it like a stack of plates: you take the top plate first.

A queue, on the other hand, follows the First In, First Out (FIFO) principle — the first element added is the first one removed. It works like a line at a ticket counter.

Both are used to manage ordered data, but their access patterns are different. Stacks are useful for backtracking algorithms, like undo functionality, and queues are great for scheduling tasks or handling asynchronous events.

한국어 번역

스택은 후입선출 (LIFO, Last In First Out) 원칙을 따르는 자료구조입니다. 가장 마지막에 들어온 요소가 가장 먼저 나갑니다. 접시를 쌓아 올리는 것처럼, 맨 위에 있는 접시를 먼저 꺼내는 방식과 같습니다.

반면 큐는 선입선출 (FIFO, First In First Out) 원칙을 따릅니다. 먼저 들어온 데이터가 먼저 나가는 구조입니다. 매표소 앞 줄과 같이 생각하면 이해하기 쉽습니다.

둘 다 순차적으로 데이터를 관리하는 데 사용되지만, 접근 방식(access patterns)이 다르기 때문에 용도에 따라 선택됩니다. 스택은 되돌리기 기능처럼 순서를 역순으로 처리해야 할 때 유용하고, 큐는 작업 스케줄링(scheduling tasks)이나 비동기 이벤트 처리(asynchronous events)에 자주 사용됩니다.

주요 표현 정리

  • Last In, First Out (LIFO): 후입선출
  • First In, First Out (FIFO): 선입선출
  • access patterns: 접근 방식
  • scheduling tasks: 작업 스케줄링
  • asynchronous events: 비동기 이벤트

Answer 2: Operational behavior and use cases

English

The main difference between a stack and a queue lies in how elements are inserted and removed.

In a stack, elements are added and removed from the same end, called the top. This means you can only access the most recently added item. Common operations are push (add) and pop (remove).

In a queue, elements are added at the rear and removed from the front. This maintains the original order of processing. Typical operations are enqueue (add) and dequeue (remove).

Use a stack when you need to reverse order or backtrack, and a queue when order needs to be preserved, like in task queues, print jobs, or BFS traversal.

한국어 번역

스택과 큐의 가장 큰 차이점은 데이터를 어디에서 넣고 꺼내느냐에 있습니다.

스택은 데이터를 한쪽 끝(top)에서 넣고 꺼냅니다. 즉, 가장 최근에 추가된 항목만 접근할 수 있습니다. 일반적으로 사용하는 연산은 push(추가)와 pop(제거)입니다.

큐는 데이터를 뒤쪽(rear)에서 넣고 앞쪽(front)에서 꺼냅니다. 따라서 처리 순서가 보존됩니다. 대표적인 연산은 enqueue(추가)와 dequeue(제거)입니다.

스택은 순서를 뒤집거나 되돌릴 필요가 있을 때 사용하고, 큐는 순서를 그대로 유지하며 처리해야 할 때 사용합니다. 예를 들어, 작업 큐(task queues), 프린터 작업(print jobs), 너비 우선 탐색(BFS traversal) 등입니다.

주요 표현 정리

  • push / pop: 스택에서의 삽입 / 제거 연산
  • enqueue / dequeue: 큐에서의 삽입 / 제거 연산
  • rear / front: 큐의 뒤 / 앞
  • task queues: 작업 큐
  • print jobs: 프린터 작업
  • BFS traversal: 너비 우선 탐색

학습 자료

AI 튜터

디자인

업로드

수업 노트

즐겨찾기

도움말

What is the difference between a stack and a queue?