C-CAT Data Structures Revision: Topic-wise Guide
Data structures for C-CAT
Data structures questions in Section B are short and conceptual: which structure fits a situation, what an operation costs, what a traversal prints, or what a snippet does to a list. This guide organises the revision by topic and lists the facts you should be able to recall without thinking.
Topic checklist
| Topic | Be able to |
|---|---|
| Complexity | Read Big-O for loops and recursion; know best, average and worst cases |
| Arrays | Compute address of an element; insertion and deletion cost |
| Linked lists | Singly, doubly, circular; insert, delete, reverse |
| Stacks | LIFO, push and pop, infix to postfix, postfix evaluation |
| Queues | FIFO, circular queue, deque, priority queue |
| Trees | Terminology, traversals, binary search tree operations |
| Heaps | Min-heap and max-heap, heapify, build-heap cost |
| Graphs | Adjacency matrix vs list, BFS, DFS |
| Searching and sorting | Compare algorithms by time, space and stability |
| Hashing | Hash functions, collisions, chaining and open addressing |
Complexity at a glance
| Operation | Typical cost |
|---|---|
| Access array element by index | O(1) |
| Insert at the beginning of an array | O(n) |
| Insert at the head of a linked list | O(1) |
| Search in an unsorted list | O(n) |
| Binary search on a sorted array | O(log n) |
| BST search, balanced | O(log n) |
| BST search, skewed | O(n) |
| Push, pop on a stack | O(1) |
| Enqueue, dequeue | O(1) |
| Build a heap | O(n) |
Rule of thumb: a loop that halves the problem each time is O(log n); nested loops over the same input are O(n^2).
Linked lists
- A singly linked list gives O(1) insertion at the head but O(n) at the tail unless a tail pointer is kept.
- Reversing a list means changing the
nextpointers, using three pointers: previous, current and next. - Deleting a node from a singly linked list needs access to the previous node.
- A doubly linked list stores two pointers per node, so it uses more memory but lets you traverse both ways.
- Detecting a cycle is done with two pointers moving at different speeds.
Stacks and queues
- A stack is LIFO. Uses: function calls, undo, expression evaluation, balanced bracket checks.
- A queue is FIFO. Uses: scheduling, buffering, BFS.
- In a circular queue of size
n, the queue is full when(rear + 1) % n == front. - A priority queue serves the element with the highest priority first, and is usually built on a heap.
- Infix to postfix: operands go straight out; operators wait on a stack; pop operators of higher or equal precedence before pushing a new one.
^is right-associative, so it is handled differently. - Postfix evaluation: scan left to right, push operands, and on an operator pop two values (the first popped is the right operand), apply it and push the result.
Trees
- Traversals of a binary tree: inorder (left, root, right), preorder (root, left, right), postorder (left, right, root).
- Inorder traversal of a binary search tree gives sorted order.
- A binary tree with
nnodes hasn - 1edges. - The maximum number of nodes at level
l(root at level 0) is2^l, and a tree of heighthhas at most2^(h+1) - 1nodes. - A tree can be rebuilt from inorder plus either preorder or postorder, but not from preorder plus postorder alone in general.
- AVL trees keep the balance factor of every node between -1 and 1 using rotations, so search stays O(log n).
- A heap is a complete binary tree, which is why it can be stored in an array: the children of index
iare at2i + 1and2i + 2.
Graphs
- An adjacency matrix uses O(V^2) space and checks an edge in O(1). An adjacency list uses O(V + E) space and suits sparse graphs.
- BFS uses a queue and finds the shortest path in an unweighted graph.
- DFS uses a stack or recursion and is used for cycle detection and topological sorting.
- A graph with
Vvertices that is a tree has exactlyV - 1edges.
Sorting and searching
| Algorithm | Best | Average | Worst | Stable |
|---|---|---|---|---|
| Bubble sort | O(n) | O(n^2) | O(n^2) | Yes |
| Insertion sort | O(n) | O(n^2) | O(n^2) | Yes |
| Selection sort | O(n^2) | O(n^2) | O(n^2) | No |
| Merge sort | O(n log n) | O(n log n) | O(n log n) | Yes |
| Quick sort | O(n log n) | O(n log n) | O(n^2) | No |
| Heap sort | O(n log n) | O(n log n) | O(n log n) | No |
Binary search needs a sorted array and runs in O(log n). Linear search works on any list in O(n).
Hashing
- A good hash function spreads keys evenly and is fast to compute.
- Chaining keeps colliding keys in a list at the same slot. Open addressing probes for another free slot (linear probing, quadratic probing, double hashing).
- The load factor is the number of stored keys divided by the table size; performance drops as it approaches 1.
Revise and practise
- Data Structures Cheat Sheet for one-page revision
- Data Structures Flashcards to test recall
- C Programming revision guide, since data structure questions are written in C
- C-CAT Section B Preparation Guide for the overall checklist
- C-CAT syllabus for the full topic list
Key takeaways
- Learn the complexity table; many questions are only about cost.
- Trees and stacks produce the most questions, so give them the most time.
- Practise traversals and infix to postfix on paper.
- Know which sorting algorithms are stable and what their worst case is.
Frequently Asked Questions
1 Which data structures topics matter most for C-CAT?
Stacks, queues, linked lists, binary trees and traversals, binary search trees, sorting and searching, and time complexity are the core. Graph basics such as BFS and DFS are worth knowing too.
2 Do I need to write code for data structures in C-CAT?
C-CAT is an MCQ exam, so you are more likely to trace a short snippet or pick the correct complexity than write a full program. Understanding how each operation works is what matters.
3 What is the time complexity to remember for sorting?
Bubble, insertion and selection sort are O(n^2) in the worst case. Merge sort is O(n log n) always. Quick sort is O(n log n) on average and O(n^2) in the worst case. Heap sort is O(n log n).
4 How do I convert infix to postfix quickly?
Scan left to right, send operands straight to the output, and use a stack for operators, popping operators of higher or equal precedence before pushing a new one. Practise this on paper until it is automatic.
5 How many days should I give data structures?
A focused revision takes about 4 to 6 days if you already know the basics. Spend most of the time on trees, stacks and complexity, because they produce the most questions.