BSc CSIT (TU) Science Data Structures and Algorithms (BSc CSIT, CSC206) Question Paper 2079 Nepal
This is the official BSc CSIT (TU) (Science stream) Data Structures and Algorithms (BSc CSIT, CSC206) question paper for 2079, 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 2079 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt any TWO questions.
What is sorting? Explain the working mechanism of quick sort algorithm with a suitable example. Analyze its best-case and worst-case time complexity.
Sorting
Sorting is the process of arranging the elements of a list/array in a particular order, either ascending or descending, according to some key. Sorting makes searching and other operations more efficient.
Quick Sort
Quick sort is a divide-and-conquer, in-place sorting algorithm. It picks an element as the pivot and partitions the array so that all elements smaller than the pivot lie to its left and all larger lie to its right. The pivot then occupies its final sorted position. The two sub-arrays are sorted recursively.
Algorithm
QUICKSORT(A, low, high)
if low < high then
p = PARTITION(A, low, high) // pivot final index
QUICKSORT(A, low, p - 1)
QUICKSORT(A, p + 1, high)
PARTITION(A, low, high) // last element as pivot
pivot = A[high]
i = low - 1
for j = low to high - 1 do
if A[j] <= pivot then
i = i + 1
swap A[i] and A[j]
swap A[i+1] and A[high]
return i + 1
Example
Sort A = [7, 2, 1, 6, 8, 5, 3, 4], pivot = last element.
- Pivot = 4. After partition:
[2,1,3,4,8,5,7,6], pivot 4 placed at index 3. - Left
[2,1,3]→ pivot 3 →[2,1,3], then[2,1]→[1,2]. - Right
[8,5,7,6]→ pivot 6 →[5,6,8,7], then[8,7]→[7,8]. - Final sorted array:
[1, 2, 3, 4, 5, 6, 7, 8].
Time Complexity Analysis
Best case — the pivot splits the array into two nearly equal halves at every level. The recurrence is:
Average case is also .
Worst case — the pivot is always the smallest or largest element (e.g. an already sorted array with last/first as pivot), giving one empty and one size- partition:
Space complexity is on average (recursion stack). Randomised pivot selection avoids the worst case in practice.
Define a binary search tree (BST). Write algorithms for insertion and deletion of a node in a BST and trace them with a suitable example.
Binary Search Tree (BST)
A Binary Search Tree is a binary tree in which, for every node :
- all keys in the left subtree of are less than 's key, and
- all keys in the right subtree of are greater than 's key.
This ordering allows search, insertion and deletion in time, where is the tree height ( if balanced, in the worst case).
Insertion Algorithm
INSERT(root, key)
if root == NULL then
return new Node(key)
if key < root.key then
root.left = INSERT(root.left, key)
else if key > root.key then
root.right = INSERT(root.right, key)
return root
Trace — insert 50, 30, 70, 20, 40, 60, 80 into an empty BST:
50
/ \
30 70
/ \ / \
20 40 60 80
Each key is compared from the root and placed as a leaf following the BST property.
Deletion Algorithm
Three cases: leaf, one child, two children.
DELETE(root, key)
if root == NULL then return NULL
if key < root.key then
root.left = DELETE(root.left, key)
else if key > root.key then
root.right = DELETE(root.right, key)
else // node found
if root.left == NULL then return root.right // 0 or right child
if root.right == NULL then return root.left // left child only
succ = MIN(root.right) // inorder successor
root.key = succ.key
root.right = DELETE(root.right, succ.key)
return root
Trace — delete 30 (a node with two children) from the tree above:
- Inorder successor of 30 = smallest in its right subtree = 40.
- Copy 40 into the node, then delete the original 40 (a leaf).
50
/ \
40 70
/ / \
20 60 80
Deleting a leaf (e.g. 20) simply removes it; deleting a node with one child links its child to its parent.
What is a graph? Explain Breadth First Search (BFS) and Depth First Search (DFS) traversal techniques with suitable examples and their applications.
Graph
A graph is a non-linear data structure consisting of a set of vertices and a set of edges connecting pairs of vertices. Graphs may be directed/undirected and weighted/unweighted.
Consider the undirected graph:
A - B
| | \
C - D - E
Adjacency: A:{B,C}, B:{A,D,E}, C:{A,D}, D:{B,C,E}, E:{B,D}.
Breadth First Search (BFS)
BFS explores the graph level by level, visiting all neighbours of a vertex before moving deeper. It uses a queue.
BFS(G, s)
mark all vertices unvisited
enqueue s; mark s visited
while queue not empty do
v = dequeue()
visit v
for each unvisited neighbour w of v do
mark w visited; enqueue w
Order from A: A, B, C, D, E.
Depth First Search (DFS)
DFS explores as deep as possible along each branch before backtracking. It uses a stack (or recursion).
DFS(G, v)
mark v visited; visit v
for each unvisited neighbour w of v do
DFS(G, w)
Order from A: A, B, D, C, E (depends on neighbour ordering).
Comparison & Applications
| Aspect | BFS | DFS |
|---|---|---|
| Data structure | Queue | Stack/recursion |
| Strategy | Level-wise | Depth-wise |
| Shortest path (unweighted) | Yes | No |
Both run in time using adjacency lists.
Applications of BFS: shortest path in unweighted graphs, peer-to-peer networks, web crawlers, finding connected components.
Applications of DFS: cycle detection, topological sorting, finding strongly connected components, solving mazes/puzzles, spanning trees.
Section B: Short Answer Questions
Attempt any EIGHT questions.
What is algorithm complexity? Explain Big-O, Big-Omega and Theta notations with examples.
Algorithm Complexity
Algorithm complexity measures the amount of resources (mainly time and space) an algorithm needs as a function of the input size . Asymptotic notations describe its growth rate for large , ignoring constants and lower-order terms.
Big-O () — upper bound (worst case). if there exist constants such that for all . Example: linear search is ; inserting in an array is .
Big-Omega () — lower bound (best case). if for all . Example: any comparison sort is ; linear search best case is .
Big-Theta () — tight bound. if for all , i.e. both and hold. Example: merge sort is ; summing an array is .
For instance, is , and therefore .
What is a linked list? Differentiate between singly and doubly linked lists with diagrams.
Linked List
A linked list is a linear data structure where elements (nodes) are stored at non-contiguous memory locations, each node containing data and one or more pointers to other nodes. Unlike arrays, it has dynamic size and allows insertion/deletion given a node reference.
Singly Linked List (SLL)
Each node has data and a single next pointer to the following node; the last node points to NULL. Traversal is one-directional (forward only).
[10|*]->[20|*]->[30|NULL]
Doubly Linked List (DLL)
Each node has data, a next pointer and a prev pointer, allowing bidirectional traversal.
NULL<-[*|10|*]<->[*|20|*]<->[*|30|*]->NULL
Differences
| Feature | Singly Linked List | Doubly Linked List |
|---|---|---|
| Pointers per node | 1 (next) | 2 (prev, next) |
| Traversal | Forward only | Both directions |
| Memory per node | Less | More (extra pointer) |
| Delete given a node | Need previous node | Direct (prev available) |
| Implementation | Simpler | More complex |
Define a queue. Explain circular queue and write an algorithm for its enqueue and dequeue operations.
Queue
A queue is a linear data structure that follows the FIFO (First In, First Out) principle: elements are inserted at the rear and removed from the front.
Circular Queue
In a simple linear array queue, once rear reaches the last index, no new element can be added even if front positions are free (false overflow). A circular queue treats the array as circular: after the last index, the next position wraps to index 0 using modulo arithmetic, reusing freed space efficiently.
For a queue of size : it is full when (rear + 1) % N == front, and empty when front == -1.
Enqueue Algorithm
ENQUEUE(Q, x)
if (rear + 1) % N == front then
print "Queue Overflow"; return
if front == -1 then
front = 0
rear = (rear + 1) % N
Q[rear] = x
Dequeue Algorithm
DEQUEUE(Q)
if front == -1 then
print "Queue Underflow"; return
x = Q[front]
if front == rear then // only one element
front = rear = -1
else
front = (front + 1) % N
return x
Both operations run in time.
What is recursion? Write a recursive algorithm to compute the factorial of a number and explain the role of the stack in recursion.
Recursion
Recursion is a technique in which a function calls itself (directly or indirectly) to solve a problem by reducing it to smaller instances of the same problem. A valid recursive function must have:
- A base case that stops the recursion, and
- A recursive case that moves toward the base case.
Recursive Factorial
FACTORIAL(n)
if n == 0 then // base case
return 1
else
return n * FACTORIAL(n - 1) // recursive case
E.g. FACTORIAL(4) = 4*3*2*1*1 = 24.
Role of the Stack
Each recursive call creates a new activation record (stack frame) pushed onto the call stack, storing the parameters, local variables and return address. Frames pile up until the base case is reached:
fact(4) -> fact(3) -> fact(2) -> fact(1) -> fact(0)=1 (pushing)
Then the stack unwinds as each call returns, multiplying results: . The maximum stack depth equals the recursion depth ( space); a missing base case causes infinite recursion and stack overflow.
Differentiate between bubble sort and selection sort with examples.
Bubble Sort vs Selection Sort
Bubble Sort repeatedly steps through the list, compares adjacent elements and swaps them if out of order, so the largest unsorted element 'bubbles' to its place each pass.
Selection Sort repeatedly selects the minimum element from the unsorted part and places it at the beginning, performing at most one swap per pass.
Differences
| Feature | Bubble Sort | Selection Sort |
|---|---|---|
| Basic idea | Swap adjacent out-of-order pairs | Select minimum and place in order |
| Swaps | Many () | Few (, one per pass) |
| Comparisons | ||
| Best case | (with early-exit flag) | |
| Stable | Yes | No (default) |
| Adaptive | Yes (can detect sorted) | No |
Both have worst- and average-case time and use extra space.
Example on [5, 1, 4, 2]
Bubble sort (pass 1): compare/swap adjacent → [1,4,2,5]; pass 2 → [1,2,4,5]; sorted.
Selection sort: min is 1 → [1,5,4,2]; next min 2 → [1,2,4,5]; next min 4 → [1,2,4,5]; sorted.
Explain inorder, preorder and postorder tree traversals with an example binary tree.
Tree Traversal
Traversal means visiting every node of a tree exactly once in a systematic order. The three depth-first traversals differ in when the root is visited relative to its subtrees.
- Inorder (Left, Root, Right): traverse left subtree → visit root → traverse right subtree. For a BST this yields keys in sorted ascending order.
- Preorder (Root, Left, Right): visit root → left subtree → right subtree. Useful to copy a tree or produce prefix expressions.
- Postorder (Left, Right, Root): left subtree → right subtree → visit root. Useful to delete a tree or produce postfix expressions.
Example Binary Tree
A
/ \
B C
/ \ \
D E F
- Inorder: D, B, E, A, C, F
- Preorder: A, B, D, E, C, F
- Postorder: D, E, B, F, C, A
INORDER(node)
if node != NULL:
INORDER(node.left); visit(node); INORDER(node.right)
(Preorder and postorder reorder the visit call accordingly.)
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 requirement | Works on unsorted or sorted | Requires sorted data |
| Method | Check elements one by one | Repeatedly halve the search range |
| Time complexity | ||
| Best case | ||
| Data structure | Array/linked list | Array (random access) |
Binary Search Algorithm
Given a sorted array A[0..n-1] and a key:
BINARY_SEARCH(A, n, key)
low = 0; high = n - 1
while low <= high do
mid = low + (high - low) / 2
if A[mid] == key then
return mid // found
else if A[mid] < key then
low = mid + 1 // search right half
else
high = mid - 1 // search left half
return -1 // not found
Complexity Analysis
Each iteration halves the search space, so the number of comparisons satisfies:
- Best case: (key at middle).
- Worst/average case: .
- Space: iterative, recursive.
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 holds the maximum).
- Min-heap: every parent its children (root holds the minimum).
It is usually stored in an array where, for index (0-based), children are at and and the parent at . Heaps power the priority queue and heap sort.
Heapify
Heapify (sift-down) restores the heap property at a node assuming its subtrees are already heaps: compare the node with its children, swap with the larger child (for max-heap), and recurse downward until the property holds. It costs . Building a heap from elements by heapifying from the last internal node upward costs .
Building a Max-Heap from 4, 10, 3, 5, 1
Insert into a complete binary tree (array [4,10,3,5,1]):
4
/ \
10 3
/ \
5 1
Heapify from the last internal node up (indices 1 then 0):
- Node 10 (index 1): children 5,1 — already largest. No change.
- Node 4 (index 0): children 10 and 3; largest child 10 > 4 → swap.
10
/ \
4 3
/ \
5 1
- Re-heapify the displaced 4 (now index 1): children 5,1; 5 > 4 → swap.
10
/ \
5 3
/ \
4 1
Final max-heap array: [10, 5, 3, 4, 1].
Explain different representations of a graph (adjacency matrix and adjacency list) with examples.
Graph Representations
A graph can be stored mainly in two ways. Consider the directed example with vertices and edges .
1. Adjacency Matrix
A matrix where (or the edge weight) if an edge exists from to , else 0.
1 2 3 4
1 0 1 1 0
2 0 0 0 1
3 0 0 0 1
4 0 0 0 0
- Space: .
- Edge lookup: .
- Best for dense graphs.
2. Adjacency List
An array/list of lists, where list holds all vertices adjacent to .
1 -> 2 -> 3
2 -> 4
3 -> 4
4 -> (empty)
- Space: .
- Edge lookup: .
- Best for sparse graphs; preferred by BFS/DFS.
Comparison
| Feature | Adjacency Matrix | Adjacency List |
|---|---|---|
| Space | ||
| Check edge | ||
| Iterate neighbours | ||
| Suited for | Dense graphs | Sparse graphs |
Frequently asked questions
- Where can I find the BSc CSIT (TU) Data Structures and Algorithms (BSc CSIT, CSC206) question paper 2079?
- The full BSc CSIT (TU) Data Structures and Algorithms (BSc CSIT, CSC206) 2079 (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) 2079 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) 2079 paper?
- The BSc CSIT (TU) Data Structures and Algorithms (BSc CSIT, CSC206) 2079 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.