Foundations of Data Structures and Algorithms MCQs for the NSCT
Foundations of Data Structures and Algorithms is the groundwork of the DSA area: abstract data types (ADTs), what makes something an algorithm, asymptotic notation (Big-O, Omega and Theta) and recursion. It is the first of 12 topics in Data Structures & Algorithms, which carries 10% of the NSCT according to HEC's Areas of Competencies.
DSA was one of the weaker areas in 2026, with 40.2% average accuracy per the HEC NSCT report and APP. Everything later in the area, from sorting to hashing, is judged with the tools on this page.
ADTs
An abstract data type is a set of values plus the operations allowed on them, described by behaviour only. A data structure is a concrete way to store the data and code those operations.
| ADT (what) | Possible data structures (how) |
|---|---|
| Stack: push, pop, top | Array, singly linked list |
| Queue: enqueue, dequeue | Circular array, linked list with tail pointer |
| Priority queue: insert, remove-min | Sorted array, binary heap |
| Map: put, get | Hash table, balanced BST |
One ADT can have several implementations with different costs. A priority queue on a sorted array inserts in O(n); on a binary heap it inserts in O(log n).
An algorithm is a finite sequence of well-defined steps that turns input into output. Knuth lists five properties: finiteness, definiteness, input, output and effectiveness. Being written in a particular language is not one of them.
Exam angle: if an option names behaviour only ("priority queue"), it is an ADT; if it names a layout ("binary heap in an array"), it is a data structure.
Asymptotic notation
Asymptotic notation describes how running time or memory grows as input size n grows, ignoring constants and small terms.
| Notation | Meaning | Example |
|---|---|---|
| f = O(g) | Upper bound: f(n) ≤ c·g(n) for large n | 3n + 5 = O(n), and also O(n²) |
| f = Ω(g) | Lower bound: f(n) ≥ c·g(n) for large n | n² = Ω(n) |
| f = Θ(g) | Tight bound: both O(g) and Ω(g) | 3n² + 100n = Θ(n²) |
| f = o(g) | Strictly slower, for every c > 0 | n = o(n²) |
The usual growth order is 1 < log n < √n < n < n log n < n² < 2ⁿ < n!.
To find the cost of code, count how many times the innermost statement runs:
for i in range(n): # n times
j = 1
while j < n: # about log2(n) times
j *= 2
This is O(n log n). Nested loops multiply, loops in sequence add, and a counter that halves or doubles gives log n.
Keep best, worst and average case separate from O, Ω and Θ. Cases describe which input you analyse; the notations describe bounds. Insertion sort's worst case is Θ(n²) and its best case (sorted input) is Θ(n). Amortised cost averages over a whole sequence of operations, as with appending to a doubling dynamic array.
Exam angle: many questions ask for the tightest bound. O(n³) is a true but loose bound for 3n² + 7.
Recursion
Recursion is when a function solves a problem by calling itself on a smaller instance. Every recursive function needs a base case that stops the calls and a recursive case that moves towards it.
def fact(n):
if n <= 1: # base case
return 1
return n * fact(n - 1)
fact(5) returns 120. Each pending call keeps a frame on the call stack, so this uses O(n) extra space. A missing or unreachable base case fills the stack until it overflows; Python raises RecursionError.
A tail-recursive function makes its recursive call as its last action. Some compilers reuse the frame for this (tail-call optimisation), but CPython does not.
To cost a recursive algorithm, write a recurrence. T(n) = T(n - 1) + n unrolls to n(n + 1)/2 = Θ(n²). Naive Fibonacci, T(n) = T(n - 1) + T(n - 2) + 1, makes an exponential number of calls; memoisation cuts it to O(n).
Exam angle: for output questions, note whether the print happens before the recursive call (output on the way down) or after it (output on the way back, in reverse).
Common traps
- Treating Big-O as "exact running time". It is an upper bound only; Θ is the tight one.
- Equating worst case with Big-O and best case with Omega. Any case can be described with any of the three notations.
- Multiplying a doubling outer loop by an inner loop of i steps and getting n log n. The sum 1 + 2 + 4 + ... < 2n, so it is O(n).
- Forgetting the stack space of recursion. Recursive factorial uses O(n) space even with no array.
- Assuming the base of a logarithm matters. log₂ n and log₁₀ n differ only by a constant factor.
- Reading the order of prints wrongly when output comes after the recursive call.
Worked examples
1. Understanding. Which notation states only that an algorithm needs at least c·g(n) steps for large n? Answer: Big-Omega (Ω). It is a lower bound. Big-O is an upper bound and Θ is both.
2. Application. How many times does the body run in i = 1; while i <= 81: i *= 3?
Answer: 5. i takes the values 1, 3, 9, 27 and 81 before reaching 243, so the loop is O(log₃ n).
3. Analysis. A function on input n does O(1) work and calls itself twice on n/2, stopping at n ≤ 1. A classmate says it is O(log n) because n halves each time. Is that right? Answer: no. The recurrence is T(n) = 2T(n/2) + 1. The depth is log n, but the number of calls doubles at each level: 1 + 2 + 4 + ... + n, about 2n calls (2,047 for n = 1,024). It is Θ(n).
Practise
The quiz below has 97 questions on this topic, filterable by tier and difficulty.
Practise: 97 questions
FAQs
What is the difference between an ADT and a data structure?
An ADT says what operations are available and how they behave, for example a stack's push and pop. A data structure is a concrete storage layout that implements those operations, such as an array or a linked list. The same ADT can be built on different structures, each with different costs.
Is Big-O the same as worst-case time?
No, although they are often used together. Big-O is a type of bound (an upper bound), while worst case is a choice of input (the slowest one of size n). You can state a worst-case running time with Θ, and you can give an O bound for the best case. Textbooks such as CLRS keep the two ideas separate.
Is recursion slower than a loop?
Usually by a constant factor, because each call creates a stack frame, and recursion also uses O(depth) extra memory. The asymptotic time is often the same. Recursion becomes dramatically slower only when it repeats work, as naive Fibonacci does; memoisation or an iterative version removes that.
How do I find the time complexity of a loop quickly?
Ask how the loop counter changes. Adding a constant each step gives n iterations; multiplying or dividing by a constant gives log n. Then multiply for nested loops and add for loops in sequence, keeping only the fastest-growing term. When the inner loop depends on the outer counter, add up the actual counts.
Next step
Move on to Linear Data Structures MCQs, see all topics on the DSA MCQs hub, or test yourself in an NSCT mock test.