NSCT Data Structures & Algorithms Revision Notes
These notes condense all 12 official Data Structures & Algorithms topics into the complexities, traces, formulas and traps you need for fast recall. DSA carries 10% of the NSCT, according to HEC's Areas of Competencies. In 2026 candidates averaged 40.2% accuracy in it, one of the four weakest areas, per the HEC NSCT report and APP.
How to use them: read a topic, then trace its MCQs on paper through the link under it, and log each miss in an error log with the step where you went wrong. HEC's report put accuracy at 49.5% for Understanding, 45.1% for Application and 44.8% for Analysis questions. In DSA, application means executing an algorithm (a traversal, a sort pass, a probe sequence), so practise by hand.
Foundations of Data Structure and Algorithms
| Notation | Meaning |
|---|---|
| O(g) | Upper bound (3n + 5 is O(n) and also O(n²)) |
| Ω(g) | Lower bound |
| Θ(g) | Tight bound: both O and Ω |
- An ADT says what (stack: push, pop); a data structure says how (array or linked list).
- Best, worst and average case are separate from O, Ω and Θ.
- Recursion needs a base case; each pending call uses stack space, so recursive factorial is O(n) space.
- Amortised cost averages over a sequence, as with doubling-array appends.
Trap: equating worst case with Big-O and best case with Omega. Any case can use any notation. Practise: Foundations MCQs.
Linear Data Structures
| Operation | Array | Singly linked list (head only) |
|---|---|---|
| Access i-th | O(1) | O(n) |
| Insert at front | O(n) | O(1) |
| Insert at end | O(1) amortised | O(n), O(1) with tail pointer |
- Row-major A[i][j] = base + (i × cols + j) × size.
- Stack is LIFO; queue is FIFO. Circular queues wrap indices with % n.
- In postfix evaluation, pop the right operand first for − and /.
Trap: assuming linked-list insertion is always O(1). It is O(1) only once you are at the position. Practise: Linear Data Structures MCQs and stack and queue applications.
Non-Linear Data Structures
- Max nodes in a binary tree of height h: 2^(h+1) − 1. Leaves = two-child nodes + 1. Edges = n − 1.
- BST: left subtree smaller, right subtree larger (whole subtrees, not just children).
- Heap: complete tree; parent ≤ children (min-heap). Insert and remove O(log n); build O(n); arbitrary search O(n).
- Adjacency matrix: Θ(V²) space, O(1) edge check. Adjacency list: Θ(V + E).
Trap: assuming BST search is always O(log n). An unbalanced BST is O(n). Practise: Non-Linear Data Structures MCQs.
Searching Algorithms
- Linear search: average successful (n + 1)/2 comparisons; worst n.
- Binary search needs sorted, random-access data; worst case ⌊log₂ n⌋ + 1 probes (10 for 1,000 items).
- Interpolation search averages O(log log n) only on uniformly distributed keys.
- Jump search O(√n); exponential search O(log i).
Trap: binary search on a linked list. Reaching the middle costs O(n), so it is no faster than linear. Practise: Searching MCQs.
Sorting Algorithms
| Algorithm | Best | Worst | Extra space | Stable |
|---|---|---|---|---|
| Bubble (flag) | O(n) | O(n²) | O(1) | Yes |
| Selection | O(n²) | O(n²) | O(1) | No |
| Insertion | O(n) | O(n²) | O(1) | Yes |
| Merge | O(n log n) | O(n log n) | O(n) | Yes |
| Quick | O(n log n) | O(n²) | O(log n) average | No |
| Heap | O(n log n) | O(n log n) | O(1) | No |
- Bubble sort swaps = number of inversions.
- Counting and radix sort are not comparison sorts, so they escape Ω(n log n).
Trap: calling heap sort stable because it is always O(n log n). Practise: Sorting MCQs and sorting comparison.
Hashing
- Load factor α = n/m (keys ÷ slots). Open addressing needs α ≤ 1.
- Division method: choose a prime m not close to a power of 2.
- Linear probing → primary clustering; quadratic → secondary clustering; double hashing avoids both.
- Deleting in open addressing needs a tombstone.
- O(1) is the expected case; the worst case is O(n).
Trap: forgetting to wrap around from slot m − 1 to slot 0 when probing. Practise: Hashing MCQs.
Tree Algorithms
| Traversal | Order |
|---|---|
| Preorder | node, left, right |
| Inorder | left, node, right (sorted for a BST) |
| Postorder | left, right, node |
| Level order | by depth, using a queue |
- Inorder plus preorder (or postorder) rebuilds a unique tree; preorder plus postorder does not.
- AVL: LL → right rotation; RR → left; LR and RL need double rotations.
- A B-tree grows in height only when the root splits.
Trap: classifying an AVL case by the unbalanced node alone instead of where the new key went. Practise: Tree Algorithms MCQs and tree traversals.
Graph Algorithms
| Algorithm | Problem | Negative edges? | Time |
|---|---|---|---|
| BFS | Shortest paths, unweighted | n/a | O(V + E) |
| Dijkstra | Single source | No | O((V + E) log V) |
| Bellman-Ford | Single source | Yes | O(VE) |
| Floyd-Warshall | All pairs | Yes, no negative cycles | O(V³) |
- BFS uses a queue; DFS a stack or recursion.
- Kruskal sorts edges and uses union-find; Prim grows one tree.
- An MST has V − 1 edges. Kahn's algorithm outputting fewer than V vertices means a cycle.
Trap: using Dijkstra with a negative edge. Practise: Graph Algorithms MCQs and graph traversal traces.
Algorithm Design Techniques
| Technique | Examples |
|---|---|
| Divide and conquer | Merge sort, quicksort, binary search |
| Greedy | Huffman, Kruskal, Prim, Dijkstra, activity selection |
| Dynamic programming | 0/1 knapsack, LCS, edit distance, Floyd-Warshall |
| Backtracking | N-Queens, Sudoku, subset sum |
- DP needs optimal substructure and overlapping subproblems.
- Greedy by ratio is optimal for fractional knapsack, not 0/1.
- Greedy coin change fails for coins 1, 3, 4.
Trap: calling Dijkstra or Prim dynamic programming. Most textbooks, including CLRS, class them as greedy. Practise: Design Techniques MCQs and dynamic programming.
Advanced Data Structures
- Trie search and insert are O(L) for a key of length L; an end-of-word flag marks stored words.
- Segment tree: O(log n) range query and point update; Fenwick tree does the same with less memory.
- No updates → prefix sums (O(1) query).
- Union-find with union by rank and path compression: O(α(n)) amortised.
- B-tree (CLRS minimum degree t): non-root nodes hold t − 1 to 2t − 1 keys.
Trap: treating a prefix path as a stored word when its end-of-word flag is false. Practise: Advanced Data Structures MCQs.
String Algorithms
| Algorithm | Worst-case matching | Key idea |
|---|---|---|
| Naive | O((n − m + 1) m) | Try every shift |
| KMP | O(n + m) total | Prefix function; text pointer never moves back |
| Rabin-Karp | O((n − m + 1) m), expected O(n + m) | Rolling hash, then verify |
- There are n − m + 1 shifts; overlapping matches count ("aba" occurs 3 times in "abababa").
- Prefix function of ABABCABAB: [0, 0, 1, 2, 0, 1, 2, 3, 4].
Trap: assuming a hash match is a real match. Rabin-Karp must verify characters. Practise: String Algorithms MCQs.
Complexity & Optimization
| Recurrence | Solution |
|---|---|
| T(n) = T(n/2) + 1 | Θ(log n) |
| T(n) = 2T(n/2) + n | Θ(n log n) |
| T(n) = T(n − 1) + n | Θ(n²) |
| T(n) = 2T(n − 1) + 1 | Θ(2ⁿ) |
- Master theorem: compare f(n) with n^(log_b a). Case 2 adds a log factor.
- Sequential loops add; nested loops multiply.
- Space complexity includes the recursion stack.
Trap: applying the master theorem to T(n − 1) recurrences. Unroll them instead. Practise: Complexity MCQs and Big-O practice.
Most-tested comparisons
| Pair | Key difference |
|---|---|
| Stack vs queue | LIFO vs FIFO |
| Array vs linked list | O(1) access vs O(1) insert at a known position |
| BFS vs DFS | Queue, shortest unweighted paths vs stack or recursion |
| Merge vs quick sort | Stable, O(n) space, always n log n vs in place, O(n²) worst |
| Dijkstra vs Bellman-Ford | No negative edges, faster vs handles negatives |
| Prim vs Kruskal | One growing tree vs merging forest |
| Greedy vs DP | Local choice, never undone vs stored subproblem answers |
| Heap vs BST | Parent vs children order vs whole-subtree order |
| Chaining vs open addressing | Lists per slot vs probing inside the table |
Last-48-hours checklist
- Recite the sorting table, including stability.
- Write preorder, inorder and postorder for one seven-node tree.
- Trace BFS and DFS on a small graph with alphabetical neighbour order.
- Run Dijkstra on a five-vertex graph.
- Build an MST with Kruskal and with Prim; confirm the same total.
- Insert five keys with linear probing, including a wrap-around.
- Solve three master-theorem recurrences.
- Count iterations for nested loops and a doubling loop.
- Do one AVL insertion that needs a double rotation.
- Compute a KMP prefix function by hand.
- Evaluate one postfix expression with a stack.
- Name which design technique fits knapsack, Huffman and N-Queens.
- Redo your error log, then one timed set in subject-wise mock tests.
Keep the DSA cheat sheet for its complexity table, and use the DSA MCQ hub for the full topic list.
FAQs
Why do students score low in DSA?
The 2026 average was 40.2%, per HEC's report. HEC does not break this down by topic, but DSA questions often ask you to execute an algorithm step by step or work out a complexity, not just recall a definition. Tracing on paper and checking each step against a worked answer is the fix.
Which DSA topics should I revise first?
Start with Big-O and loop counting, because complexity questions appear across every topic. Then sorting, trees and graphs, which carry the most hand-tracing. Leave advanced structures and string algorithms until the core is solid.
Do I need to write code for DSA questions?
Mostly you read and trace rather than write. Expect pseudocode or short code fragments where you predict output, count iterations or spot a bug. If you can dry-run a loop with a trace table and know the standard algorithms step by step, you are ready.
How many hours should I give DSA?
Our recommendation is about 6 hours out of a 60-hour subject plan, in line with its 10% weightage, with extra time if a diagnostic shows DSA is weak for you. The 8-week plan and 30-day plan both schedule it.
What should I do in the last week?
Stop learning new structures. Work through the checklist above, redo your error log and take timed sets. The 7-day plan gives DSA a dedicated block alongside the other weak areas.
Next step
Start with Big-O practice, then test every area together in an NSCT mock test.