The programme guide lists arrays, linked lists, stacks and queues for this unit. You will study them in depth in MCS-208 (Data Structures and Algorithms); here you see how each is built in Python using the tools of this unit. The printed unit does not include this material, so this section has no study-material section numbers.
Arrays
An array is a sequence of items of the same type stored next to each other in memory, accessed by index in constant time. In Python:
Option
What it is
Use when
list
A dynamic array of references to objects of any type
Almost always
array.array (standard library)
A compact array of one numeric type, like a C array, e.g. array('i', [1, 2, 3])
Many numbers, memory matters
NumPy ndarray
Fast multi-dimensional numeric array
Numerical computing
Linked lists
A linked list is a chain of nodes, where each node stores a value and a reference to the next node. Inserting at the front takes constant time (no shifting), but reaching item i means walking from the head. Python has no built-in linked list, so we build nodes with a small class. (Classes are covered fully in Unit 13; here a class is just a template for an object with two fields.)
A linked list holding 30, 20, 10
head │ ▼[30 | ●]──►[20 | ●]──►[10 | None]
Stacks
A stack supports push (add to the top) and pop (remove from the top). A Python list is a ready-made stack: append() pushes and pop() pops, both in constant time at the end of the list. Stacks are used for undo features, browser back buttons, expression evaluation and function calls.
Queues
A queue is First In, First Out (FIFO), like a ticket counter line: enqueue at the rear, dequeue from the front. Use collections.deque (a double-ended queue): append() adds at the rear and popleft() removes from the front, both in constant time. A list’s pop(0) also works but is slow for long lists, because every remaining item shifts one place left.
Structure
Order
Python tool
Add
Remove
Stack
LIFO
list
append(x)
pop()
Queue
FIFO
collections.deque
append(x)
popleft()
Linked list
Link order
Your own Node class
Link a new node
Relink around a node
Array
By index
list, array.array
append, insert
pop, del
Key takeaways
A list is a dynamic array; array.array stores one numeric type compactly.
A linked list is nodes joined by references; insertion at the front is constant time.
Stack = LIFO with append/pop; queue = FIFO with deque.append/popleft.
These structures are studied in depth in MCS-208.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Explain why collections.deque is preferred over a list for a queue.
Show worked answer
A queue removes items from the front. With a list, pop(0) removes the first item and then shifts every remaining item one place to the left, so it takes time proportional to the length of the list (O(n)). A deque is designed for fast operations at both ends: append() and popleft() each take constant time (O(1)), however many items the queue holds.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/data-structures-and-control-statements-in-python/arrays-linked-lists-stacks-and-queues/ to read this page.