BSc CSIT (TU) Science Design and Analysis of Algorithms (BSc CSIT, CSC314) Question Paper 2082 Nepal
This is the official BSc CSIT (TU) (Science stream) Design and Analysis of Algorithms (BSc CSIT, CSC314) question paper for 2082, as set in the annual (regular) 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 2082 paper is a great way to practise under real exam conditions.
| Level | BSc CSIT (TU) |
|---|---|
| Stream | Science |
| Subject | Design and Analysis of Algorithms (BSc CSIT, CSC314) |
| Year | 2082 BS |
| Exam session | Regular (annual) |
| Full marks | 60 |
| Time allowed | 180 minutes |
| Questions | 12, all with step-by-step solutions |
Section A: Long Answer Questions
Attempt any TWO questions.
How do you define optimal solution? Does greedy algorithm always guarantee optimal solution? Given the string "SUPER DUPER CSIT", use a Greedy algorithm to build a Huffman tree.
Optimal Solution
An optimal solution is a feasible solution that gives the best possible value of the objective function for an optimization problem — the maximum (e.g., maximum profit) or minimum (e.g., minimum cost/length) among all feasible solutions. A feasible solution merely satisfies the constraints; an optimal one is feasible and best.
Does Greedy Always Guarantee Optimal?
No. A greedy algorithm builds a solution step by step, always making the locally best (greedy) choice in the hope of reaching a globally optimal solution. It is optimal only for problems that exhibit the:
- Greedy-choice property — a globally optimal solution can be reached by local optimal choices, and
- Optimal substructure — an optimal solution contains optimal solutions to subproblems.
When these hold, greedy is optimal (e.g., fractional knapsack, Huffman coding, Dijkstra, MST). When they do not, greedy can fail:
- 0/1 knapsack — greedy by value/weight ratio is not optimal.
- Coin change with arbitrary denominations (e.g., {1, 3, 4} for amount 6).
So greedy guarantees an optimal solution only for a restricted class of problems.
Huffman Tree for "SUPER DUPER CSIT"
Step 1 — Frequency count
String = SUPER DUPER CSIT (length 16, including 2 spaces).
| Char | S | U | P | E | R | (space) | D | C | I | T |
|---|---|---|---|---|---|---|---|---|---|---|
| Freq | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 1 | 1 | 1 |
Total = 2+2+2+2+2+2+1+1+1+1 = 16. ✓
Step 2 — Greedy merging (always merge the two smallest frequencies)
Use a min-priority queue. Repeatedly extract the two lowest-frequency nodes, merge them into a parent whose frequency is their sum, and reinsert.
- Merge
D(1)+C(1)→ node DC(2) - Merge
I(1)+T(1)→ node IT(2) - Now all remaining = freq 2: {S,U,P,E,R,sp,DC,IT}. Merge
S(2)+U(2)→ SU(4) - Merge
P(2)+E(2)→ PE(4) - Merge
R(2)+sp(2)→ R_sp(4) - Merge
DC(2)+IT(2)→ DCIT(4) - Remaining freq-4 nodes {SU, PE, R_sp, DCIT}. Merge
SU(4)+PE(4)→ SUPE(8) - Merge
R_sp(4)+DCIT(4)→ R_sp_DCIT(8) - Merge
SUPE(8)+R_sp_DCIT(8)→ ROOT(16)
Step 3 — Huffman tree (assign 0 = left, 1 = right)
ROOT(16)
/ \
(0) (1)
SUPE(8) R_sp_DCIT(8)
/ \ / \
SU(4) PE(4) R_sp(4) DCIT(4)
/ \ / \ / \ / \
S U P E R sp DC(2) IT(2)
/ \ / \
D C I T
Step 4 — Resulting Huffman codes
| Char | Code | Length |
|---|---|---|
| S | 000 | 3 |
| U | 001 | 3 |
| P | 010 | 3 |
| E | 011 | 3 |
| R | 100 | 3 |
| (space) | 101 | 3 |
| D | 1100 | 4 |
| C | 1101 | 4 |
| I | 1110 | 4 |
| T | 1111 | 4 |
Step 5 — Cost
Encoded bits bits, versus bits for fixed 4-bit codes — Huffman is more efficient.
(Codes may differ depending on tie-breaking order, but lengths and total cost stay the same.)
What is order statistics? Write and analyze the algorithm for randomized quick sort.
Order Statistics
The -th order statistic of a set of elements is the element with rank — i.e., the -th smallest element. Special cases:
- → minimum
- → maximum
- → median
The selection problem is to find the -th order statistic of an unordered array. A trivial method sorts the array in then indexes position . Better, the Randomized-Select algorithm (based on randomized partition) finds it in expected time, and the deterministic median-of-medians algorithm achieves worst-case .
Randomized Quicksort
Quicksort sorts by partitioning an array around a pivot and recursing on both sides. In randomized quicksort, the pivot is chosen uniformly at random from the subarray, so the expected running time is independent of the input order and the deterministic worst case (e.g., already-sorted input) is avoided with high probability.
RandomizedQuicksort(A, p, r):
if p < r:
q = RandomizedPartition(A, p, r)
RandomizedQuicksort(A, p, q-1)
RandomizedQuicksort(A, q+1, r)
RandomizedPartition(A, p, r):
i = Random(p, r) // random index in [p, r]
swap A[i], A[r] // move random pivot to end
return Partition(A, p, r)
Partition(A, p, r): // Lomuto partition
x = A[r] // pivot
i = p - 1
for j = p to r-1:
if A[j] <= x:
i = i + 1
swap A[i], A[j]
swap A[i+1], A[r]
return i + 1
Analysis
Partition cost: each Partition is .
Worst case: — occurs only if every random pivot is the smallest/largest, which is extremely unlikely.
Best case: — pivot splits the array into two balanced halves: .
Expected (average) case: Let = total number of comparisons. Two elements of ranks are compared at most once, with probability
Then
where is the -th harmonic number. Hence the expected running time is .
- Space: expected recursion-stack depth.
- Randomization guarantees expected time on every input, with the case occurring with vanishing probability.
Distinguish between dynamic programming and memorization. Parenthesize the matrices A(30 × 1), B(1 × 40), C(40 × 10) and A(10 × 15), for computing matrix multiplication using dynamic programming.
Dynamic Programming vs. Memoization
Both avoid recomputing overlapping subproblems, but differ in approach:
| Aspect | Dynamic Programming (tabulation) | Memoization |
|---|---|---|
| Approach | Bottom-up: solve smallest subproblems first, build up | Top-down: recursive, cache results on the way down |
| Direction | Iterative, fills a table in order | Recursion + lookup table |
| Subproblem coverage | Solves all subproblems | Solves only the subproblems actually needed |
| Overhead | No recursion overhead | Recursion (function-call) overhead |
| Order | Must determine a correct evaluation order | Order handled automatically by recursion |
| Stack | No risk of deep recursion | Risk of stack overflow on deep recursion |
In short, memoization is the top-down, lazy form of dynamic programming, whereas classic DP (tabulation) is the bottom-up, eager form. Both run in the same asymptotic time when all subproblems are needed.
Matrix Chain Multiplication
(The four matrices are interpreted as a chain whose adjacent dimensions agree: A(30×1), B(1×40), C(40×10), D(10×15).)
Dimension array: , so .
Recurrence
Length-1 chains
Length-2 chains
Length-3 chains
:
→ (split at ).
:
→ (split at ).
Length-4 chain (final)
:
→ , optimal split at .
Optimal Parenthesization
- splits at :
- splits at :
Optimal parenthesization: — combining: , then gives
with minimum cost = 1000 scalar multiplications.
Section B: Short Answer Questions
Attempt any EIGHT questions.
Solve the recurrence relation T(n) = 2T(n/2) + n using recursion tree method.
Solving T(n) = 2T(n/2) + n by Recursion Tree
Build the tree
Each node represents the non-recursive (combine/divide) cost at that call. The root has cost and two children of size , each of cost , and so on.
Level Subproblems Cost per node Cost per level
0 (root) 1 n n
1 2 n/2 2·(n/2) = n
2 4 n/4 4·(n/4) = n
... ... ... ...
i 2^i n/2^i 2^i·(n/2^i) = n
... ... ... ...
last n leaves Θ(1) Θ(n)
Cost per level
At level there are nodes, each costing , so each level contributes exactly .
Height of the tree
The subproblem size at level is . Recursion stops when . So there are levels.
Total cost
The leaf level contributes , which is dominated by the term.
(Verification by the Master Theorem: , → case 2 → . ✓)
Find the best and worst case for Bubble sort.
Bubble Sort — Best and Worst Case
Bubble sort repeatedly steps through the list, compares adjacent pairs, and swaps them if out of order; after each pass the largest remaining element "bubbles" to its place.
BubbleSort(A, n):
for i = 1 to n-1:
swapped = false
for j = 1 to n-i:
if A[j] > A[j+1]:
swap A[j], A[j+1]
swapped = true
if not swapped: break // optimization: array already sorted
Best Case
Occurs when the array is already sorted. With the swapped flag optimization, the first pass makes no swaps, so the algorithm stops after one pass.
- Comparisons: , Swaps: .
- Best-case time complexity = (linear).
(Without the optimization, even the best case is .)
Worst Case
Occurs when the array is in reverse sorted order, so every comparison results in a swap.
- Pass does comparisons; total
comparisons, and the same order of swaps.
- Worst-case time complexity = (quadratic).
Summary
| Case | Condition | Comparisons | Time |
|---|---|---|---|
| Best | Already sorted | ||
| Average | Random order | ||
| Worst | Reverse sorted |
Space complexity (in-place); bubble sort is stable.
Using Extended Euclidean Algorithm, find the GCD of 12 and 16.
Extended Euclidean Algorithm — GCD(12, 16)
The Extended Euclidean Algorithm computes and integers (Bézout coefficients) such that
We compute (taking ).
Step 1 — Euclidean division (forward)
| Step | Division | Quotient | Remainder |
|---|---|---|---|
| 1 | |||
| 2 |
Last non-zero remainder = 4, so .
Step 2 — Back-substitution (find x, y)
From step 1: .
So
Verification
✓
Result
(equivalently with ).
Find all possible subsets of the integers that sum to 21 in the array {5, 6, 10, 11, 15} using back tracking technique.
Subset-Sum by Backtracking — target 21 in {5, 6, 10, 11, 15}
We seek all subsets whose elements sum to 21. Backtracking builds the subset incrementally: at each index we include or exclude the element, pruning a branch as soon as the partial sum exceeds the target.
Pruning rules
Let sum = current partial sum, remaining = sum of not-yet-considered elements.
- Prune if
sum > 21(overshoot). - Prune if
sum + remaining < 21(can never reach target). - Record the subset when
sum == 21.
Backtrack(i, sum, chosen):
if sum == 21: output chosen; return
if i > n or sum > 21: return
// include A[i]
Backtrack(i+1, sum + A[i], chosen + A[i])
// exclude A[i]
Backtrack(i+1, sum, chosen)
State-space exploration (A = {5, 6, 10, 11, 15})
We look for combinations summing to 21:
- ✓
- no single element 16.
- ✓
- ✓
- (already found); , , , ✓ (same as above)
- Check 3-element: ✓; (prune); others overshoot.
Solution Subsets (sum = 21)
| # | Subset | Sum |
|---|---|---|
| 1 | {5, 6, 10} | 21 |
| 2 | {6, 15} | 21 |
| 3 | {10, 11} | 21 |
Three subsets of the array sum to 21: {5, 6, 10}, {6, 15}, and {10, 11}.
Worst-case time complexity of subset-sum backtracking is , but pruning prunes large portions of the search tree in practice.
Define class P and NP problem. Why do we need approximation algorithms? Justify.
Class P
Class P (Polynomial time) is the set of decision problems that can be solved by a deterministic algorithm in polynomial time for some constant . These are regarded as tractable / efficiently solvable. Examples: sorting, searching, shortest path, minimum spanning tree.
Class NP
Class NP (Nondeterministic Polynomial time) is the set of decision problems whose proposed solution (certificate) can be verified in polynomial time by a deterministic algorithm — equivalently, solvable in polynomial time on a nondeterministic machine. Examples: SAT, Hamiltonian cycle, subset-sum, graph colouring. Note ; whether is the famous open question.
Why Do We Need Approximation Algorithms? (Justification)
Many important problems are NP-Hard / NP-Complete, so no known algorithm solves them exactly in polynomial time, and (assuming ) none exists. For large inputs, exact (exponential) methods are infeasible. Approximation algorithms address this by:
- Running in polynomial time — practical even for large inputs.
- Guaranteeing a provable bound on solution quality via an approximation ratio , e.g., a result within factor of the optimum (a 2-approximation for vertex cover guarantees a cover at most twice the optimum).
- Producing near-optimal solutions when an exact optimum is unnecessary or unaffordable.
Justification: For NP-Hard optimization problems (TSP, vertex cover, set cover, bin packing), we must trade a small, bounded loss in optimality for an enormous gain in running time. Approximation algorithms give the best practical compromise — fast, with quality guarantees — where exact algorithms are computationally hopeless.
State the time and space complexity for sequential search. Write the rules for master theorem for finding asymptotic bounds.
Time and Space Complexity of Sequential (Linear) Search
Sequential search scans the array element by element until the target is found or the list ends.
SequentialSearch(A, n, key):
for i = 1 to n:
if A[i] == key: return i
return -1
| Case | Condition | Time |
|---|---|---|
| Best | key is the first element | |
| Average | key equally likely anywhere | (≈ n/2 comparisons) |
| Worst | key is last or absent |
- Time complexity: (worst and average), best.
- Space complexity: — only a constant amount of extra space (a loop index). Works on unsorted data.
Master Theorem (for divide-and-conquer recurrences)
For a recurrence of the form
compare with the critical exponent . Let .
| Case | Condition | Result |
|---|---|---|
| Case 1 | for some (work dominated by leaves) | |
| Case 2 | (work balanced across levels) | |
| Case 3 | for some and regularity condition , (work dominated by root) |
Examples: Merge sort → case 2 → ; Binary search → case 2 → .
Justify the worst case for binary search. Find the edit distance from the string "RELEVANT" to "ELEPHANT" using dynamic programming approach.
Worst Case of Binary Search — Justification
Binary search on a sorted array compares the target with the middle element and discards half the remaining elements each step.
- The search space halves every comparison: .
- The worst case arises when the target is absent or found only at the deepest level, so the array must be halved until a single element remains.
- Number of halvings until size 1: .
The recurrence is , giving
This is far better than linear search's , justifying binary search for sorted data.
Edit Distance: "RELEVANT" → "ELEPHANT"
Edit (Levenshtein) distance = minimum insertions, deletions, substitutions to transform one string into the other.
Recurrence
Let = RELEVANT (m=8), = ELEPHANT (n=8). = distance between first chars of and first of .
DP Table (rows = RELEVANT, cols = ELEPHANT)
| "" | E | L | E | P | H | A | N | T | |
|---|---|---|---|---|---|---|---|---|---|
| "" | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| R | 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| E | 2 | 1 | 2 | 2 | 3 | 4 | 5 | 6 | 7 |
| L | 3 | 2 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| E | 4 | 3 | 2 | 1 | 2 | 3 | 4 | 5 | 6 |
| V | 5 | 4 | 3 | 2 | 2 | 3 | 4 | 5 | 6 |
| A | 6 | 5 | 4 | 3 | 3 | 3 | 3 | 4 | 5 |
| N | 7 | 6 | 5 | 4 | 4 | 4 | 4 | 3 | 4 |
| T | 8 | 7 | 6 | 5 | 5 | 5 | 5 | 4 | 3 |
Result
Transformation: RELEVANT → ELEVANT (delete R) → ELEPANT (substitute V→P) → ELEPHANT (insert H) = 3 operations. Time , space .
Distinguish between recursion and backtracking. Using Miller-Rabin primality test, check whether 53 is prime or not?
Recursion vs. Backtracking
| Aspect | Recursion | Backtracking |
|---|---|---|
| Definition | A function calling itself to solve smaller subproblems | A systematic search that builds candidates incrementally and abandons (backtracks) a partial solution once it cannot lead to a valid solution |
| Purpose | General problem decomposition | Solving constraint-satisfaction / combinatorial search problems |
| Exploration | Follows one defined path of subcalls | Explores a state-space tree, undoing choices when they fail |
| Pruning | No inherent pruning | Prunes invalid branches early (bounding function) |
| Examples | Factorial, Fibonacci, tree traversal | N-Queens, subset-sum, graph colouring, maze solving |
| Relationship | Backtracking uses recursion as its mechanism | A specialized, pruning form of recursion |
In short, all backtracking is recursive, but not all recursion is backtracking — backtracking adds the systematic try → check → undo search over a state-space tree.
Miller-Rabin Primality Test — Is 53 Prime?
The Miller-Rabin test checks primality of an odd . Write with odd. For a random base , is probably prime if or for some .
Step 1 — Decompose
, so . Thus .
Step 2 — Choose a base, say
Compute . . : , . So .
- and , so check the squaring sequence.
Step 3 — Square repeatedly (r = 1)
: , .
Since we found (at ), 53 passes the test for base 2.
Step 4 — Conclusion
53 passes Miller-Rabin (e.g., for base 2). Hence 53 is (probably) prime — and indeed 53 is a prime number.
How does 0/1 Knapsack problem differ from fractional one? Find the minimum vertex cover in the following graph.
0/1 Knapsack vs. Fractional Knapsack
| Aspect | 0/1 Knapsack | Fractional Knapsack |
|---|---|---|
| Item selection | Each item taken wholly (1) or not at all (0) | Any fraction of an item may be taken |
| Solution technique | Dynamic programming (greedy fails) | Greedy (sort by value/weight ratio) |
| Optimality of greedy | Greedy is not optimal | Greedy is optimal |
| Time complexity | (pseudo-polynomial) | (dominated by sorting) |
| Problem class | NP-complete (decision version) | Polynomial-time solvable |
The key difference: divisibility. Because fractional knapsack lets us fill the leftover capacity exactly using a fraction of the best-ratio item, the greedy choice is provably optimal (exchange argument). In 0/1 knapsack, indivisibility leaves "gaps" that greedy cannot fix, so DP is required.
Minimum Vertex Cover
A vertex cover is a set of vertices such that every edge has at least one endpoint in the set. The minimum vertex cover is the smallest such set. (Finding the exact minimum is NP-Hard in general; a standard 2-approximation repeatedly picks both endpoints of an uncovered edge.)
Approximation Algorithm (2-approximation)
ApproxVertexCover(G):
C = {}
E' = all edges of G
while E' not empty:
pick any edge (u, v) from E'
add u and v to C
remove from E' every edge incident on u or v
return C
Example
Consider a graph with edges: (1-2), (1-3), (2-3), (3-4), (4-5).
- Pick edge (1-2): add {1, 2}; remove edges incident on 1 or 2 → removes (1-2),(1-3),(2-3). Remaining: (3-4),(4-5).
- Pick edge (3-4): add {3, 4}; remove (3-4),(4-5). Remaining: none.
- Cover returned = {1, 2, 3, 4} (size 4, a valid 2-approximation).
The true minimum vertex cover here is {1, 3, 4} (size 3): it covers (1-2) via 1, (1-3)/(2-3) via 1 and 3, (3-4) via 3/4, (4-5) via 4. Every edge is covered, so the minimum vertex cover size is 3.
(For an arbitrary graph supplied in the question, apply the same rule: select vertices until every edge is incident to a chosen vertex; the smallest such set is the minimum vertex cover.)
Frequently asked questions
- Where can I find the BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) question paper 2082?
- The full BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) 2082 (Regular (annual)) 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) 2082 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) 2082 paper?
- The BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) 2082 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.