A list is an ordered collection of items that can grow or shrink dynamically. Unlike arrays, lists do not have a fixed size. Items can be added or removed at any position.
fruits = ["apple", "banana", "cherry"]A stack is a last-in, first-out (LIFO) data structure. Items are added and removed from the same end, called the top.
| Operation | Name | Description |
|---|---|---|
| Add item to top | Push | Places new item at the top of the stack |
| Remove item from top | Pop | Removes and returns the top item |
| View top item | Peek/Top | Returns top item without removing it |
| Check if empty | isEmpty | Returns True if stack has no items |
Stack analogy: a pile of plates. You always add to the top and remove from the top. You can't access the bottom plate without removing those above it first.
Real-world uses of stacks:
A queue is a first-in, first-out (FIFO) data structure. Items are added at the rear (back) and removed from the front.
| Operation | Name | Description |
|---|---|---|
| Add item to rear | Enqueue | Adds new item at the back of the queue |
| Remove item from front | Dequeue | Removes and returns the front item |
| View front item | Peek/Front | Returns front item without removing it |
| Check if empty | isEmpty | Returns True if queue has no items |
Queue analogy: a line of people at a bus stop. The first person to join is the first to board the bus (FIFO).
Real-world uses of queues:
| Feature | Stack | Queue |
|---|---|---|
| Ordering | LIFO (Last In, First Out) | FIFO (First In, First Out) |
| Add operation | Push (to top) | Enqueue (to rear) |
| Remove operation | Pop (from top) | Dequeue (from front) |
| Access | Top only | Front and rear |
| Example use | Undo function, browser back | Print queue, CPU scheduler |
8 questions · Edexcel-style
| Term | Definition |
|---|
10 minutes · Exam-style