BSc CSIT (TU) Science Design and Analysis of Algorithms (BSc CSIT, CSC314) Question Paper 2077 Nepal
This is the official BSc CSIT (TU) (Science stream) Design and Analysis of Algorithms (BSc CSIT, CSC314) question paper for 2077, 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 2077 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt any TWO questions.
Explain the greedy method of algorithm design. Generate the prefix code for the string "CYBER CRIME" using Huffman algorithm and find the total number of bits required to encode it.
Greedy Method
The greedy method builds a solution piece by piece, always choosing the option that looks best (locally optimal) at the current step, without reconsidering earlier choices. It works correctly only when the problem has the greedy-choice property (a global optimum can be reached by local choices) and optimal substructure.
General structure:
Greedy(C): // C = set of candidates
S = {} // solution
while C != {} and not solution(S):
x = select(C) // best candidate by greedy criterion
C = C - {x}
if feasible(S + x): S = S + x
return S
Examples: Huffman coding, Kruskal/Prim MST, Dijkstra, fractional knapsack, job sequencing.
Huffman Code for "CYBER CRIME"
String = CYBER CRIME (length 11 including the space). Frequencies:
| Symbol | C | R | E | Y | B | (space) | I | M |
|---|---|---|---|---|---|---|---|---|
| Freq | 2 | 2 | 2 | 1 | 1 | 1 | 1 | 1 |
Total = 11. Build the Huffman tree by repeatedly merging the two lowest-frequency nodes.
- Merge Y(1)+B(1) → 2
- Merge ' '(1)+I(1) → 2
- Merge M(1) with C(2) → 3
- Merge R(2)+E(2) → 4
- Merge (Y B)=2 + ( I)=2 → 4
- Merge (M C)=3 + (R E)=4 → 7
- Merge (YB I)=4 + (M C R E)=7 → 11 (root)
A valid set of resulting prefix codes (depths give code lengths):
| Symbol | Freq | Code | Bits | Freq×Bits |
|---|---|---|---|---|
| C | 2 | 100 | 3 | 6 |
| R | 2 | 110 | 3 | 6 |
| E | 2 | 111 | 3 | 6 |
| M | 2* | 101 | 3 | 6 |
| Y | 1 | 0000 | 4 | 4 |
| B | 1 | 0001 | 4 | 4 |
| (sp) | 1 | 0010 | 4 | 4 |
| I | 1 | 0011 | 4 | 4 |
Total bits bits.
With a fixed 8-symbol alphabet, naive fixed-length coding needs bits/symbol bits; Huffman is optimal for the given frequency distribution and here yields 40 bits for the full string (codes are prefix-free, so no separator is needed). Average code length bits/symbol.
Note: Several tie-break orderings give equally optimal trees; the total weighted bit count for these frequencies is the same.
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 that incrementally builds candidates to a solution and abandons a candidate ("backtracks") as soon as it determines the candidate cannot lead to a valid solution. It performs a depth-first traversal of an implicit state-space tree, pruning branches that violate constraints.
Backtracking vs Recursion
| Recursion | Backtracking |
|---|---|
| A function calling itself to solve subproblems | A problem-solving paradigm that uses recursion |
| Explores all paths/returns directly | Explores choices, prunes infeasible ones using bounding/constraint checks |
| No notion of "undoing" a choice | Explicitly undoes a choice on failure and tries the next |
| General control mechanism | Systematic, pruned search over a state space |
So backtracking is a strategy built on recursion plus pruning; not every recursion is backtracking.
4-Queens Problem
Place 4 queens on a 4×4 board so that no two share a row, column, or diagonal. Place one queen per row; for row choose column such that it is safe: no earlier queen in same column or on diagonals ().
Search (rows top to bottom):
- Row1: col1 → conflicts cascade, backtrack.
- Try Row1=col2:
- Row2: col4 (safe).
- Row3: col1 (safe).
- Row4: col3 (safe). ✓ Solution found.
One solution: (Row1,Col2), (Row2,Col4), (Row3,Col1), (Row4,Col3).
Board (Q = queen):
. Q . .
. . . Q
Q . . .
. . Q .
The second solution is its mirror: (Col3, Col1, Col4, Col2).
Algorithm
NQueens(board, row, n):
if row == n: report 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 (backtrack)
Time Complexity
Without pruning the upper bound is ; a queen per row reduces it to (each row tries up to columns, then , etc.). The constraint checks prune most branches, so practical performance is far better, but the worst-case is . For the tree is tiny and solved quickly.
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)
For 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 minimum among all spanning trees.
Kruskal's Algorithm
Kruskal grows the MST by adding edges in increasing weight order, skipping any edge that would form a cycle (detected with a Disjoint-Set / Union-Find structure).
Kruskal(G):
A = {} // MST edge set
for each vertex v: MakeSet(v)
sort edges E by weight ascending
for each edge (u,v) in sorted order:
if Find(u) != Find(v): // no cycle
A = A + {(u,v)}
Union(u,v)
return A
Example
Graph with edges: A-B=1, A-C=3, B-C=3, B-D=6, C-D=4, C-E=2, D-E=5.
Sort: A-B(1), C-E(2), A-C(3), B-C(3), C-D(4), D-E(5), B-D(6).
Process:
- A-B(1) → add. Sets: {A,B}
- C-E(2) → add. {C,E}, {A,B}
- A-C(3) → add (joins the two sets). {A,B,C,E}
- B-C(3) → both in same set → skip (cycle)
- C-D(4) → add. {A,B,C,D,E} — all 5 vertices, 4 edges done.
MST edges: A-B, C-E, A-C, C-D with total weight .
Complexity Analysis
- Sorting edges: .
- Union-Find operations over edges with path compression + union by rank: , nearly linear.
- Overall: (since , ). This dominates the runtime.
Section B: Short Answer Questions
Attempt any EIGHT questions.
Write Dijkstra's algorithm to find single-source shortest paths and explain it with an example.
Dijkstra's Algorithm (Single-Source Shortest Path)
Finds shortest path distances from a source to all vertices in a graph with non-negative edge weights, using a greedy approach.
Dijkstra(G, s):
for each v in V: dist[v] = INF; prev[v] = NIL
dist[s] = 0
Q = all vertices (min-priority queue keyed by dist)
while Q not empty:
u = ExtractMin(Q) // closest unfinalized vertex
for each edge (u,v) with weight w:
if dist[u] + w < dist[v]: // relaxation
dist[v] = dist[u] + w
prev[v] = u
return dist, prev
Example
Graph (directed/undirected), source = A: A-B=4, A-C=1, C-B=2, C-D=5, B-D=1.
| Step | Finalized | dist A | B | C | D |
|---|---|---|---|---|---|
| init | – | 0 | ∞ | ∞ | ∞ |
| pick A | A | 0 | 4 | 1 | ∞ |
| pick C(1) | A,C | 0 | 3 | 1 | 6 |
| pick B(3) | A,C,B | 0 | 3 | 1 | 4 |
| pick D(4) | all | 0 | 3 | 1 | 4 |
Shortest distances: A→A=0, A→B=3 (A-C-B), A→C=1, A→D=4 (A-C-B-D).
Complexity
With a binary-heap priority queue: ; with a simple array: .
Explain the matrix chain multiplication problem and write its dynamic programming formulation.
Matrix Chain Multiplication
Given a chain of matrices where has dimension , find the parenthesization that minimizes the number of scalar multiplications. Matrix multiplication is associative, so the result is fixed, but the cost depends on the order: multiplying a and matrix costs scalar multiplications.
The number of parenthesizations grows like the Catalan numbers (exponential), so brute force is infeasible — hence dynamic programming.
DP Formulation
Let = minimum cost to compute .
- Base case: (single matrix, no multiplication).
- Recurrence: for ,
The index is the split point; we store to reconstruct the optimal parenthesization.
MatrixChainOrder(p[0..n]):
for i = 1 to n: m[i][i] = 0
for L = 2 to n: // chain length
for i = 1 to n-L+1:
j = i+L-1
m[i][j] = INF
for k = i to j-1:
q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]
if q < m[i][j]: m[i][j] = q; s[i][j] = k
return m[1][n]
Complexity
Three nested loops over each: time , space . The answer is .
Explain heap sort algorithm with an example and analyze its time complexity.
Heap Sort
Heap sort uses a binary max-heap (a complete binary tree stored in an array where every parent ≥ its children). It has two phases:
- Build max-heap from the input array.
- Repeatedly extract the max (swap root with last element, shrink heap, sift down) to place elements in sorted order.
Array indexing (0-based): for node , children are and , parent is .
HeapSort(A, n):
for i = n/2 - 1 downto 0: Heapify(A, n, i) // build max-heap
for i = n-1 downto 1:
swap(A[0], A[i]) // largest to its final position
Heapify(A, i, 0) // restore heap on reduced size
Heapify(A, n, i):
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]); Heapify(A,n,largest)
Example
Sort [4, 10, 3, 5, 1].
- Build max-heap →
[10, 5, 3, 4, 1]. - Swap 10↔1 →
[1,5,3,4,|10], heapify →[5,4,3,1,|10]. - Swap 5↔1 →
[1,4,3,|5,10], heapify →[4,1,3,|5,10]. - Swap 4↔3 →
[3,1,|4,5,10], heapify →[3,1,...]. - Swap 3↔1 →
[1,|3,4,5,10].
Sorted: [1, 3, 4, 5, 10].
Time Complexity
- Build-heap: .
- extractions, each : .
- Best, average, and worst case: . In-place, space ; not stable.
Explain how the subset-sum problem is solved using backtracking with an example.
Subset-Sum via Backtracking
Problem: Given a set of positive integers and a target , find a subset whose elements sum exactly to .
Backtracking idea: Build a binary state-space tree — at each element decide to include it or exclude it. Prune a branch when:
- current sum exceeds (overshoot), or
- current sum + sum of remaining elements < (can never reach target).
Elements are usually sorted ascending to make bounding effective.
SubsetSum(i, currSum, remaining):
if currSum == T: report solution; return
if i == n or currSum > T or currSum + remaining < T: return // prune
// include w[i]
SubsetSum(i+1, currSum + w[i], remaining - w[i])
// exclude w[i]
SubsetSum(i+1, currSum, remaining - w[i])
Example
, target .
- Total remaining = 21.
- Include 3 (sum=3) → include 5 (8) → include 6 (14) → include 7 (21>15) ✗; exclude 7 (14≠15) ✗.
- Include 3 (3) → include 5 (8) → exclude 6 → include 7 (15) ✓ → subset {3, 5, 7} = 15.
- Continuing also finds {3, 6, ...} no; another solution is none further equal.
Solution subset: {3, 5, 7} (sum 15).
Complexity
Worst case (binary choice per element); bounding functions prune large portions of the tree in practice.
What are approximation algorithms? Explain the approximation algorithm for the vertex cover problem.
Approximation Algorithms
Many optimization problems are NP-hard, so no known polynomial-time algorithm produces the exact optimum. An approximation algorithm runs in polynomial time and produces a solution provably close to optimal. Its quality is measured by the approximation ratio : for a minimization problem, , where is the algorithm's cost and the optimal. An algorithm with ratio is called a -approximation.
Approximation for Vertex Cover
Vertex Cover: find a minimum-size set of vertices such that every edge has at least one endpoint in . This is NP-hard. A simple 2-approximation:
ApproxVertexCover(G):
C = {}
E' = E(G)
while E' is not empty:
pick any edge (u,v) from E'
C = C + {u, v} // add BOTH endpoints
remove from E' all edges incident to u or v
return C
Why it is a 2-approximation: The edges picked in the loop form a matching (no two share a vertex). Any vertex cover must include at least one endpoint of each picked edge, so (number of picked edges) . Hence , giving approximation ratio 2.
Runtime: . The algorithm is guaranteed never to exceed twice the optimal cover size.
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 (typically NP-hard) by systematically exploring a state-space tree. At each node it computes a bound — an optimistic estimate (lower bound for minimization) of the best solution obtainable in that subtree. If a node's bound is worse than the best complete solution found so far (the incumbent), the entire subtree is pruned (not explored).
Key elements:
- Branching: split the problem into subproblems (children nodes).
- Bounding: compute a lower/upper bound for each node.
- Pruning: discard nodes that cannot improve the incumbent.
- Search order may be BFS (FIFO), DFS (LIFO), or best-first (least-cost) using a priority queue.
Unlike backtracking (which only checks feasibility), B&B uses a cost bound to prune even feasible-but-suboptimal branches.
B&B for Travelling Salesman Problem (TSP)
TSP: find a minimum-cost tour visiting every city exactly once and returning to the start.
State-space tree: each level fixes the next city in the tour. For each node compute a lower bound on the cost of any complete tour through that partial path. A common bound:
adjusted as edges are committed along the partial path.
Procedure:
- Start at city 1; compute root lower bound.
- Branch to each unvisited city; for each child compute its lower bound from the reduced cost matrix.
- Use a priority queue (best-first): expand the node with the smallest bound.
- When a complete tour is reached, update the incumbent (best tour cost).
- Prune any node whose bound ≥ incumbent.
- Continue until the queue is empty; the incumbent is the optimal tour.
B&B avoids exploring the full permutations by pruning, though the worst case remains exponential.
Differentiate between Breadth First Search (BFS) and Depth First Search (DFS) with examples and their time complexities.
BFS vs DFS
Both are graph-traversal algorithms visiting every vertex/edge, but differ in order and data structure.
| Feature | BFS | DFS |
|---|---|---|
| Data structure | Queue (FIFO) | Stack (LIFO) / recursion |
| Exploration | Level by level (nearest first) | Goes as deep as possible, then backtracks |
| Finds shortest path (unweighted) | Yes (fewest edges) | No (not in general) |
| Memory | , can be wide () | , proportional to depth |
| Applications | Shortest path, level-order, bipartite check, connected components | Topological sort, cycle detection, SCC, path finding |
| Completeness | Complete | Complete on finite graphs |
Example
Graph: A–B, A–C, B–D, C–D, D–E. Start at A.
- BFS order: A, B, C, D, E (visit A's neighbors first, then theirs).
- DFS order: A, B, D, C, E (or A, B, D, E, C depending on neighbor order) — dives deep before backtracking.
Time Complexity
For a graph with vertices and edges, using adjacency lists both run in:
Using an adjacency matrix, both are . Space complexity is for the queue/stack and visited array.
Solve the recurrence relation T(n) = 2T(n/2) + n using the substitution method and the recursion tree method.
Solving
(a) Substitution Method
Guess: . We prove for suitable .
Assume it holds for : . Then:
This is provided , i.e. . The induction holds, so . A matching lower bound gives .
(b) Recursion Tree Method
Expand the recurrence:
- Level 0: cost (1 node).
- Level 1: 2 nodes, each cost → total .
- Level 2: 4 nodes, each cost → total .
- Level : nodes, each cost → total .
Every level costs exactly . The tree has height (until subproblem size = 1), so the number of levels is .
Verification (Master Theorem): , → Case 2 → .
Answer: .
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 , where each job takes one unit of time and only one job runs at a time, schedule a subset of jobs (each before/at its deadline) to maximize total profit.
Greedy strategy: Sort jobs by profit in descending order. Consider each job and assign it to the latest free time slot its deadline. If no slot is free, skip the job. Picking high-profit jobs first and scheduling them as late as possible keeps earlier slots open for other jobs.
JobSequencing(jobs):
sort jobs by profit descending
maxD = max deadline; slot[1..maxD] = free
result = {}
for each job j in sorted order:
for t = min(maxD, j.deadline) downto 1:
if slot[t] is free:
slot[t] = j; add j to result; break
return result
Example
| Job | A | B | C | D | E |
|---|---|---|---|---|---|
| Deadline | 2 | 1 | 2 | 1 | 3 |
| Profit | 60 | 100 | 20 | 40 | 20 |
Sort by profit: B(100,d1), A(60,d2), D(40,d1), C(20,d2), E(20,d3).
- B(d1): slot1 free → place at slot1.
- A(d2): slot2 free → place at slot2.
- D(d1): slot1 taken → skip.
- C(d2): slots 1,2 taken → skip.
- E(d3): slot3 free → place at slot3.
Schedule: slot1=B, slot2=A, slot3=E. Selected jobs: B, A, E, maximum profit = 100 + 60 + 20 = 180.
Complexity
Sorting ; slot assignment → in the naive version (improvable to with disjoint-set for free-slot lookup).
Frequently asked questions
- Where can I find the BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) question paper 2077?
- The full BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) 2077 (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) 2077 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) 2077 paper?
- The BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) 2077 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.