Linear Data Structures MCQs for the NSCT
Linear data structures store elements in a sequence, where each element has at most one predecessor and one successor: arrays, linked lists, stacks and queues. They are the second of 12 topics in the Data Structures & Algorithms area, which carries 10% of the NSCT according to HEC's Areas of Competencies.
Expect cost questions (what is O(1) and what is O(n)?) and hand traces of push, pop, enqueue and dequeue. The Big-O tools come from Foundations of DSA.
Arrays
An array stores elements of the same size in one contiguous block, so the address of A[i] is base + i × size. That gives O(1) access by index, but inserting or deleting in the middle shifts elements, which is O(n).
For a 2D array the layout matters. Take int A[5][8] at base 1000 with 4-byte ints and 0-based indices:
| Order | Formula for A[i][j] | A[3][5] |
|---|---|---|
| Row-major (C, C++) | base + (i × cols + j) × size | 1000 + 29 × 4 = 1116 |
| Column-major (Fortran, MATLAB) | base + (j × rows + i) × size | 1000 + 28 × 4 = 1112 |
A dynamic array (Python list, C++ vector, Java ArrayList) grows by a constant factor, usually doubling, so appending is amortised O(1).
Exam angle: check whether a question uses 0-based or 1-based indices before applying the formula; with 1-based indices you subtract 1 first.
Linked lists
A linked list is a chain of nodes, each holding data and a pointer to the next node. There is no random access, but inserting at a known position only changes pointers.
| Operation | Array | Singly linked list (head only) |
|---|---|---|
| Access i-th element | O(1) | O(n) |
| Insert at front | O(n) | O(1) |
| Insert at end | O(1) amortised | O(n), or O(1) with a tail pointer |
| Delete a given node | O(n) | O(n) to find its predecessor |
A doubly linked list adds a previous pointer, so deleting a node you already hold is O(1), at the cost of one extra pointer per node. In a circular list the last node points back to the head.
Exam angle: reversing a singly linked list in place needs three pointers (previous, current, next) and is O(n) time, O(1) space.
Stacks
A stack is a last-in, first-out (LIFO) ADT with push, pop and peek, all O(1). Popping an empty stack is underflow; pushing onto a full fixed-size stack is overflow.
push 5, push 8, pop, push 3 -> [5, 3] (top = 3)
Classic uses: function calls, undo, balanced brackets, and converting and evaluating expressions. To evaluate postfix, push operands; on an operator, pop the right operand first, then the left. A linked-list stack pushes and pops at the head, because popping at the tail needs the predecessor.
Exam angle: if 1, 2, 3, 4 are pushed in order, a pop sequence that starts with 4 must continue 3, 2, 1. Sequences that break this, such as 4 2 3 1, are impossible. See stack and queue applications for full infix-to-postfix traces.
Queues
A queue is a first-in, first-out (FIFO) ADT: enqueue at the rear, dequeue at the front. Variants you need:
| Variant | Key idea |
|---|---|
| Circular queue | Indices wrap with % n, so freed slots are reused |
| Deque | Insert and delete at both ends |
| Priority queue | Removes the highest-priority item, usually with a heap |
In a circular queue that keeps one slot empty, the queue is empty when front == rear and full when (rear + 1) % n == front. It therefore holds at most n - 1 items.
Exam angle: in Python, list.pop(0) shifts every element, so a list-based queue is O(n) per dequeue. collections.deque.popleft() is O(1).
Common traps
- Mixing up row-major and column-major formulas, or multiplying by the column count in both.
- Assuming linked-list insertion is always O(1). It is O(1) only once you are at the position.
- Popping operands in the wrong order for
-and/in postfix evaluation. - Using
rear == n - 1as the full test in a circular queue, which ignores wrap-around. - Thinking binary search on a sorted linked list is O(log n). Reaching the middle costs O(n).
- Saying a single dynamic-array append is always O(1). The resize append is O(n); only the amortised cost is O(1).
Worked examples
1. Understanding. Which linear structure does breadth-first search use to hold the vertices waiting to be visited? Answer: a queue. BFS must visit vertices in the order it discovers them, which is FIFO.
2. Application. Evaluate the postfix expression 5 1 2 + 4 * + 3 -. Answer: 14. 1 2 + gives 3; 3 4 * gives 12; 5 12 + gives 17; 17 3 - gives 14.
3. Analysis. A queue is built on a singly linked list with head and tail pointers. Why enqueue at the tail and dequeue at the head, not the other way round? Answer: removing at the tail needs the node before the tail, an O(n) walk. Adding at the tail and removing at the head are both O(1).
Practise
The quiz below has 100 questions on this topic, filterable by tier and difficulty.
Practise: 100 questions
FAQs
What is the difference between linear and non-linear data structures?
In a linear structure, elements form a single sequence: each has at most one predecessor and one successor, as in arrays, lists, stacks and queues. In a non-linear structure, an element can connect to several others, as in trees and graphs. Our non-linear data structures page covers those.
When should I use a linked list instead of an array?
Use a linked list when you insert and delete often at known positions, such as the front, and rarely need the i-th element. Use an array when you need fast access by index, good cache performance or compact memory. In practice dynamic arrays win most of the time.
Is a stack an ADT or a data structure?
A stack is an ADT, because it is defined by its operations (push, pop, peek) and LIFO behaviour. An array-based stack and a linked-list stack are two data structures that implement it. Exam options often use "stack" loosely for both.
Why does a circular queue leave one slot empty?
With front == rear meaning empty, a completely full array would also give front == rear, so the two states would look the same. Keeping one slot free makes full mean (rear + 1) % n == front. The other common fix is to keep a separate count of elements.
Next step
Move on to Non-Linear Data Structures MCQs, see all topics on the DSA MCQs hub, or test yourself in an NSCT mock test.