Data Structures: Stack and Queue
Section B1, Computer Science. Covers Stack; Expression notation; Queue; Deque.
About this unit
A data structure is a way of organising data so that it can be used efficiently. This unit studies two linear data structures that limit where items are added and removed: the stack (last in, first out) and the queue (first in, first out), along with the deque, which allows both ends. It also uses a stack to convert and evaluate arithmetic expressions written in infix, prefix and postfix notation.
Key ideas
- Stack: LIFO, with PUSH, POP and peek (top) operations.
- Overflow (no space to add) and underflow (removing from an empty structure).
- Infix, prefix and postfix notation; operator precedence.
- Evaluating postfix expressions and converting infix to postfix using a stack.
- Queue: FIFO, with enqueue at the rear and dequeue at the front.
- Deque: insertion and deletion at both front and rear.
How to prepare
Trace sequences of operations on paper, writing the contents after each step. Practise five or six infix-to-postfix conversions and postfix evaluations. Learn which Python list methods implement each operation: append(), pop() and pop(0), insert(0, x).
Topics in this chapter
Stack
LIFO, PUSH and POP, and implementing a stack with a Python list.
5 questionsExpression notation
Infix, prefix and postfix; evaluating postfix and converting infix to postfix.
5 questionsQueue
FIFO, insert and delete operations and implementation with a list.
5 questionsDeque
Double-ended queue and its implementation.
5 questions