Blog
Data Structures & Algorithms Past Paper 2025 BSCS & BSSE UOS
Data Structures & Algorithms Past Paper 2025 BS Computer Science & BS Software Engineering – University of Sargodha – SU – UOS
Data Structures & Algorithms Past Paper 2025 (text version)
University of Sargodha – BS 3rd Semester Examination 2025
Subject: CS/SE · Paper: Data Structures & Algorithms (CMPC-201) · Time: 2:30 hours · Maximum marks: 40
Objective part is compulsory. Attempt any three questions from the subjective part.
Q.1 Short answers (2 × 8)
- What is divide and conquer?
- Which algorithm is faster, quick sort or merge sort?
- What is Big O notation?
- Which data structure works LIFO?
- What is a Binary Search Tree?
- What is a doubly linked list?
- What is an adjacency matrix?
- What is DFS?
Subjective part (3 × 8)
- Q.2 Write code to implement a queue with Enqueue(int item) and Dequeue() methods, and briefly explain how it works.
- Q.3 Which data structures are used to implement DFS and BFS? Explain in detail.
- Q.4 How does a circular linked list work? Write code for traversal and insertion in a circular linked list.
- Q.5 What is hashing and how is it used? What is a hash function? Show with examples.
- Q.6 Explain Big-O notation and its importance in analysing algorithm performance. Compare the time complexity of linear search and binary search.
Short questions solved
- Divide and conquer: split a problem into smaller sub-problems, solve each recursively, then combine the results (e.g. merge sort, quick sort, binary search).
- Quick sort vs merge sort: both average O(n log n). Quick sort is usually faster in practice (in-place, cache-friendly) but has an O(n²) worst case; merge sort is always O(n log n) but needs O(n) extra memory.
- Big O notation: describes an upper bound on how an algorithm’s running time or memory grows with input size n, e.g. O(1), O(log n), O(n), O(n²).
- LIFO structure: the stack (last in, first out).
- Binary Search Tree: a binary tree where every node’s left subtree holds smaller keys and its right subtree larger keys, allowing O(log n) average search.
- Doubly linked list: a list where each node stores data plus pointers to both the next and the previous node, so it can be traversed in both directions.
- Adjacency matrix: a V × V matrix representing a graph, where entry [i][j] is 1 (or the edge weight) if there is an edge from i to j, otherwise 0.
- DFS: depth-first search explores a graph by going as deep as possible along each branch before backtracking; it uses a stack (or recursion).
Solved subjective questions
Q.2 Queue (circular array, C++)
const int SIZE = 100;
class Queue {
int arr[SIZE];
int front = 0, rear = -1, count = 0;
public:
bool isEmpty() { return count == 0; }
bool isFull() { return count == SIZE; }
void Enqueue(int item) {
if (isFull()) { cout << "Queue overflow\n"; return; }
rear = (rear + 1) % SIZE; // move rear forward (wraps around)
arr[rear] = item;
count++;
}
int Dequeue() {
if (isEmpty()) { cout << "Queue underflow\n"; return -1; }
int item = arr[front];
front = (front + 1) % SIZE; // move front forward (wraps around)
count--;
return item;
}
};How it works: a queue is FIFO. Enqueue adds at the rear, Dequeue removes from the front. Using % SIZE lets the indices wrap around so freed space at the start is reused; both operations are O(1).
Q.3 DFS uses a stack (explicitly or through recursion): push the start vertex, pop a vertex, visit it if unvisited, push its unvisited neighbours – this goes deep first. BFS uses a queue: enqueue the start vertex, dequeue a vertex, visit it and enqueue its unvisited neighbours – this visits level by level and finds shortest paths in unweighted graphs. Both use a visited array and run in O(V + E) with adjacency lists.
Q.4 Circular linked list – the last node points back to the first instead of NULL, so you can keep cycling through the list; it is useful for round-robin scheduling. Traversal must stop when you return to the starting node.
struct Node { int data; Node* next; };
void traverse(Node* head) {
if (head == nullptr) return;
Node* temp = head;
do {
cout << temp->data << " ";
temp = temp->next;
} while (temp != head);
}
// insert at end; returns the (possibly new) head
Node* insertEnd(Node* head, int value) {
Node* n = new Node{value, nullptr};
if (head == nullptr) { n->next = n; return n; }
Node* temp = head;
while (temp->next != head) temp = temp->next;
temp->next = n;
n->next = head;
return head;
}Q.5 Hashing stores and finds data in (average) O(1) time by computing an index from the key. A hash function maps a key to a table index, e.g. h(k) = k mod 10: keys 23, 45, 67 go to slots 3, 5, 7. When two keys map to the same slot (e.g. 23 and 33), a collision occurs, handled by chaining (a linked list per slot) or open addressing (linear/quadratic probing). Uses: symbol tables, caches, dictionaries, password storage.
Q.6 Big-O lets us compare algorithms independent of hardware by how running time grows with n. Linear search checks elements one by one: O(n) worst/average, O(1) best. Binary search repeatedly halves a sorted array: O(log n) worst/average, O(1) best. For n = 1,000,000, linear search may need 1,000,000 comparisons, binary search about 20.
Answers prepared by Shining Study for revision. Check them against your class notes and teacher’s guidance.





