BSc CSIT (TU) Science Design and Analysis of Algorithms (BSc CSIT, CSC314) Question Paper 2078 Nepal
This is the official BSc CSIT (TU) (Science stream) Design and Analysis of Algorithms (BSc CSIT, CSC314) question paper for 2078, 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 Design and Analysis of Algorithms (BSc CSIT, CSC314) 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) Design and Analysis of Algorithms (BSc CSIT, CSC314) exam or solving previous years' question papers, this 2078 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt any TWO questions.
What is backtracking and how does it differ from recursion? Solve the 4-Queens problem using backtracking and analyze its time complexity.
Backtracking
Backtracking is an algorithmic technique for solving problems incrementally by building a solution one piece at a time and abandoning a partial candidate ("backtracking") as soon as it determines the candidate cannot possibly lead to a valid complete solution. It performs a systematic depth-first search of the state-space tree, using bounding/feasibility checks to prune branches that violate constraints.
Backtracking vs. Recursion
| Aspect | Recursion | Backtracking |
|---|---|---|
| Nature | A general technique where a function calls itself | A specific problem-solving strategy that uses recursion |
| Goal | Break a problem into smaller subproblems | Search the solution space and discard infeasible partial solutions |
| Pruning | No inherent pruning | Prunes (cuts off) branches via constraint checks (bounding function) |
| Backward step | Just returns | Undoes the last choice and tries the next alternative |
In short, backtracking is recursion + state-space search + pruning.
4-Queens Problem using Backtracking
Place 4 queens on a board so that no two attack each other (no two in the same row, column, or diagonal). We place one queen per row and try columns , backtracking when a placement is unsafe.
A placement at row , column is safe w.r.t. an earlier queen at if:
algorithm NQueens(board, row, n):
if row == n:
output solution; return
for col = 0 to n-1:
if isSafe(board, row, col):
place queen at (row, col)
NQueens(board, row+1, n)
remove queen from (row, col) // backtrack
Trace for n = 4 (board[row] = column):
- Row 0: place Q at col 0.
- Row 1: col 0,1 unsafe → col 2 safe. Place at col 2.
- Row 2: cols 0,1,2,3 all attacked → dead end, backtrack to row 1.
- Row 1: try col 3. Place at col 3.
- Row 2: only col 1 safe. Place at col 1.
- Row 3: col 0,1,2 unsafe, col 3 unsafe → dead end. Backtrack repeatedly to row 0.
- Row 0: place Q at col 1.
- Row 1: col 3 safe. Row 2: col 0 safe. Row 3: col 2 safe. Solution found.
Solution: positions :
. Q . .
. . . Q
Q . . .
. . Q .
(The second solution is its mirror: .)
Time Complexity
Without pruning, queens in rows with column choices gives an upper bound of ; restricting to one queen per column gives permutations. Each isSafe check costs , so a loose bound is . Backtracking's pruning dramatically reduces the explored nodes in practice, but the worst-case time complexity remains exponential, .
Define minimum spanning tree. Write Kruskal's algorithm to find the MST of a connected weighted graph, illustrate it with an example and analyze its complexity.
Minimum Spanning Tree (MST)
Given a connected, undirected, weighted graph , a spanning tree is a subgraph that is a tree connecting all vertices using exactly edges. A Minimum Spanning Tree is a spanning tree whose total edge weight is the minimum among all spanning trees of .
Kruskal's Algorithm
Kruskal's is a greedy algorithm that builds the MST by repeatedly adding the smallest-weight edge that does not form a cycle, using a Disjoint-Set (Union-Find) structure to detect cycles.
algorithm Kruskal(G):
A = {} // MST edge set
for each vertex v: MakeSet(v)
sort all edges E in non-decreasing order of weight
for each edge (u, v) in sorted order:
if Find(u) != Find(v): // u, v in different components -> no cycle
A = A union {(u,v)}
Union(u, v)
return A
Example
Graph with vertices and edges: .
Sort edges: .
| Edge | Weight | Forms cycle? | Action |
|---|---|---|---|
| AB | 1 | No | Add |
| BC | 2 | No | Add |
| CD | 3 | No | Add |
| AD | 4 | Yes (A,D already connected) | Reject |
| AC | 5 | Yes | Reject |
MST edges = , total weight , with edges.
Complexity Analysis
- Sorting edges: .
- Union-Find operations (with union by rank + path compression): nearly , effectively .
Overall: time (since , ). Space: .
Define asymptotic notations (Big-O, Big-Omega, Big-Theta). State the master theorem and use it to solve the recurrences T(n)=3T(n/2)+n and T(n)=2T(n/4)+sqrt(n).
Asymptotic Notations
Let and be non-negative functions.
- Big-O (Upper bound): if there exist constants such that for all . It gives the worst-case / upper growth rate.
- Big-Omega (Lower bound): if there exist such that for all . It gives a lower bound.
- Big-Theta (Tight bound): if there exist such that for all . Thus iff and .
Master Theorem
For a recurrence of the form with , let . Compare with :
- Case 1: if for some , then .
- Case 2: if , then .
- Case 3: if for some and (regularity, ), then .
Recurrence 1:
Here . .
Compare with . Since (e.g. ), Case 1 applies.
Recurrence 2:
Here . .
Compare with . They are equal, so — Case 2 applies.
Section B: Short Answer Questions
Attempt any EIGHT questions.
Explain heap sort algorithm with an example and analyze its time complexity.
Heap Sort
Heap sort is a comparison-based sorting algorithm that uses a binary max-heap (a complete binary tree where every parent its children, stored in an array).
Steps:
- Build a max-heap from the input array (heapify from the last internal node down to the root).
- Repeatedly extract the maximum: swap the root (largest) with the last element, reduce heap size by 1, and call
max-heapifyon the root to restore the heap property. - Repeat until the heap is empty; the array becomes sorted in ascending order.
HeapSort(A, n):
BuildMaxHeap(A, n)
for i = n-1 downto 1:
swap(A[0], A[i])
MaxHeapify(A, 0, i) // heap size = i
Example
Sort .
- Build max-heap: .
- Swap root 10 with last → , heapify → .
- Swap 5 → , heapify → .
- Swap 4 → , heapify → .
- Swap 3 → .
- Sorted: .
Time Complexity
BuildMaxHeap: .- Each of the extractions calls
MaxHeapifycosting → .
Total: in best, average and worst cases. It sorts in place ( extra space) but is not stable.
Explain how the subset-sum problem is solved using backtracking with an example.
Subset-Sum Problem
Given a set of positive integers and a target sum , find a subset whose elements add up to exactly .
Backtracking Approach
We explore a binary state-space tree: at each element we decide to include or exclude it. We track the running sum and prune branches using two bounding conditions (assuming elements are sorted):
- Prune if
currentSum + s[i] > W(including this element overshoots), and - Prune if
currentSum + (sum of remaining elements) < W(cannot reach ).
SubsetSum(i, currentSum, subset):
if currentSum == W: output subset; return
if i == n or currentSum > W: return
// include s[i]
if currentSum + s[i] <= W:
SubsetSum(i+1, currentSum + s[i], subset + s[i])
// exclude s[i]
if currentSum + remainingSum(i+1) >= W:
SubsetSum(i+1, currentSum, subset)
Example
, target .
- Include 3 → sum 3. Include 4 → 7. Include 5 → 12 (>9, prune). Exclude 5, include 6 → 13? no; from 7 exclude 5,exclude... reaching dead ends.
- From sum 3, exclude 4, include 5 → 8, include 6 → 14 prune; exclude 6 → dead end.
- Include 3, exclude 4, exclude 5, exclude 6 → 3 ≠ 9.
- Backtrack: exclude 3, include 4, include 5 → 9 ✓ → subset .
- Also include 3, include 6 → 9 ✓ → subset .
Solutions: and .
Complexity
The worst-case state space has nodes, so the time complexity is , though pruning reduces the search substantially in practice.
What are approximation algorithms? Explain the approximation algorithm for the vertex cover problem.
Approximation Algorithms
Many optimization problems (e.g. vertex cover, TSP) are NP-hard, so no known polynomial-time algorithm finds the exact optimum. An approximation algorithm runs in polynomial time and returns a solution guaranteed to be within a provable factor of the optimum.
For a minimization problem, an algorithm has approximation ratio if for every input the cost of its solution satisfies , where is the optimal cost.
Approximation Algorithm for Vertex Cover
A vertex cover of graph is a set of vertices that includes at least one endpoint of every edge. Finding the minimum vertex cover is NP-hard. The following greedy algorithm gives a 2-approximation:
ApproxVertexCover(G):
C = {}
E' = E
while E' is not empty:
pick any edge (u, v) from E'
add both u and v to C
remove from E' every edge incident on u or v
return C
Why it is a 2-approximation
The set of edges picked in the loop forms a matching (they share no endpoints). Any vertex cover must include at least one endpoint of each edge in , so . The algorithm adds both endpoints, so .
Thus — the solution is at most twice the optimum. Running time is .
Example: for a path , picking edge adds and covers both edges → cover (size 2 vs optimum of size 1, still within factor 2).
Explain the branch and bound technique. How is it used to solve the travelling salesman problem?
Branch and Bound
Branch and Bound (B&B) is a technique for solving optimization problems (often NP-hard) by systematically exploring the state-space tree while using bounds to prune subtrees that cannot contain an optimal solution.
- Branch: partition the problem into subproblems (children of a node).
- Bound: compute a lower bound (for minimization) on the best solution obtainable in each subtree.
- Prune: if a node's bound the cost of the best complete solution found so far, discard that subtree.
Nodes are explored using strategies such as least-cost (best-first), FIFO (BFS), or LIFO (DFS). Unlike pure backtracking (which only checks feasibility), B&B uses a cost/bound function to guide and prune the search.
Travelling Salesman Problem (TSP) with B&B
TSP: find the minimum-cost tour that visits every city exactly once and returns to the start.
Lower-bound function: A common bound is computed from the reduced cost matrix. For each row and column, subtract its minimum entry; the sum of all subtracted values is a lower bound on any tour cost.
Procedure:
- Form the cost matrix; reduce it (row + column reduction) to get the root's lower bound.
- Branch by choosing to include or exclude a particular edge , creating child nodes.
- For each child, set the chosen row / column (and the reverse edge) to , re-reduce the matrix, and add the reduction cost + edge cost to the parent's bound to get the child's bound.
- Use a priority queue to always expand the live node with the least bound (best-first search).
- When a complete tour is reached, update the best (upper bound). Prune any node whose lower bound current best.
- Continue until the least-bound live node is itself a complete tour → optimal.
B&B avoids exploring the full search space by pruning, though its worst-case time is still exponential. It guarantees the exact optimal tour.
Differentiate between Breadth First Search (BFS) and Depth First Search (DFS) with examples and their time complexities.
BFS vs. DFS
Both Breadth First Search (BFS) and Depth First Search (DFS) are graph traversal algorithms that visit every vertex once.
| Feature | BFS | DFS |
|---|---|---|
| Data structure | Queue (FIFO) | Stack (LIFO) / recursion |
| Order | Visits all neighbours level by level | Goes as deep as possible before backtracking |
| Shortest path | Finds shortest path (fewest edges) in unweighted graphs | Does not guarantee shortest path |
| Space | — stores a whole level (can be wide) | — stores the current path/recursion stack |
| Applications | Shortest path, level-order, bipartite check, broadcasting | Topological sort, cycle detection, connected components, path finding |
Time Complexity
For a graph with vertices and edges using an adjacency list, both run in . With an adjacency matrix, both run in .
Example
Graph (adjacency): , starting at .
- BFS order: (explores neighbours level by level).
- DFS order: (goes deep along , backtracks, then ).
Solve the recurrence relation T(n) = 2T(n/2) + n using the substitution method and the recursion tree method.
Recurrence:
This is the recurrence for merge sort. We solve it two ways.
(a) Substitution Method
Guess: . Prove by induction.
Assume it holds for : . Then
With :
The inductive step holds, so .
(b) Recursion Tree Method
At each level the work done equals the sum of the non-recursive terms:
| Level | # subproblems | Size each | Work per node | Work at level |
|---|---|---|---|---|
| 0 | 1 | |||
| 1 | 2 | |||
| 2 | 4 | |||
Each level contributes work. The tree has height , so there are levels.
Conclusion: (confirmed by both methods; also Master Theorem Case 2).
Explain the job sequencing with deadlines problem and solve it using the greedy approach for a given set of jobs.
Job Sequencing with Deadlines
Problem: Given jobs, each with a deadline and a profit (earned only if the job finishes by its deadline), schedule jobs on a single machine where each job takes one unit of time. Maximize total profit. Only one job runs per time slot.
Greedy Approach
- Sort all jobs in decreasing order of profit.
- Find the maximum deadline and create that many time slots (initially empty).
- For each job (highest profit first), place it in the latest free slot at or before its deadline. If no such slot is free, reject the job.
JobSequencing(jobs):
sort jobs by profit descending
slots[1..dmax] = free
for each job j:
for t = min(dmax, j.deadline) downto 1:
if slots[t] is free:
slots[t] = j; break
Example
| Job | J1 | J2 | J3 | J4 | J5 |
|---|---|---|---|---|---|
| Profit | 20 | 15 | 10 | 5 | 1 |
| Deadline | 2 | 2 | 1 | 3 | 3 |
Max deadline = 3, so slots [1][2][3].
- J1 (p20, d2): place at slot 2 → [_, J1, _].
- J2 (p15, d2): slot 2 full → slot 1 → [J2, J1, _].
- J3 (p10, d1): slot 1 full → rejected.
- J4 (p5, d3): slot 3 free → [J2, J1, J4].
- J5 (p1, d3): slots 3,2,1 full → rejected.
Schedule: J2 → J1 → J4. Maximum profit .
Complexity
Sorting is ; slot assignment is , so overall in the simple version (or near with a disjoint-set optimization).
Explain the naive string matching algorithm and the Rabin-Karp algorithm with their time complexities.
Naive String Matching
To find a pattern of length in a text of length , the naive algorithm slides over one position at a time and, at each of the shifts, compares characters one by one.
NaiveMatch(T, P):
for s = 0 to n-m:
if P[0..m-1] == T[s..s+m-1]:
report match at s
- Best case: (mismatch on first character each time).
- Worst case: (e.g. , ).
Rabin-Karp Algorithm
Rabin-Karp uses hashing to avoid comparing every character at every shift. It computes a hash of the pattern and a rolling hash of each -length window of the text; only when hashes match does it verify character by character (to handle collisions / spurious hits).
The rolling hash updates in per shift:
where is the alphabet size and a prime modulus.
RabinKarp(T, P, d, q):
compute hp = hash(P), ht = hash(T[0..m-1])
for s = 0 to n-m:
if hp == ht and P == T[s..s+m-1]:
report match at s
update ht to next window (rolling hash)
Time Complexity
| Algorithm | Average | Worst case |
|---|---|---|
| Naive | ||
| Rabin-Karp | (many hash collisions) |
With a good hash and prime , Rabin-Karp runs in on average; its worst case degrades to when spurious hits force full verification.
Write an algorithm for binary search using divide and conquer. Analyze its best-case, worst-case and average-case time complexity.
Binary Search (Divide and Conquer)
Binary search finds a key in a sorted array by repeatedly comparing with the middle element and discarding half the array each time — a classic divide-and-conquer technique.
BinarySearch(A, low, high, x):
if low > high:
return -1 // not found
mid = low + (high - low) / 2
if A[mid] == x:
return mid
else if x < A[mid]:
return BinarySearch(A, low, mid-1, x) // search left half
else:
return BinarySearch(A, mid+1, high, x) // search right half
Each step reduces the problem size to , giving the recurrence:
By the Master Theorem (, , Case 2): .
Time Complexity Analysis
| Case | When it occurs | Comparisons | Complexity |
|---|---|---|---|
| Best | Key is at the middle on the first probe | 1 | |
| Worst | Key is absent, or at an extreme; array halved until size 1 | ||
| Average | Key at a random position |
Space: for the recursive call stack ( if implemented iteratively).
Frequently asked questions
- Where can I find the BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) question paper 2078?
- The full BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) 2078 (regular) question paper is available free on Kekkei. You can read every question online and attempt the paper under timed exam conditions.
- Does the Design and Analysis of Algorithms (BSc CSIT, CSC314) 2078 paper come with solutions?
- Yes. Every question on this Design and Analysis of Algorithms (BSc CSIT, CSC314) 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) Design and Analysis of Algorithms (BSc CSIT, CSC314) 2078 paper?
- The BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) 2078 paper carries 60 full marks and is meant to be completed in 180 minutes, across 12 questions.
- Is practising this Design and Analysis of Algorithms (BSc CSIT, CSC314) past paper free?
- Yes — reading and attempting this Design and Analysis of Algorithms (BSc CSIT, CSC314) past paper on Kekkei is completely free.