BSc CSIT (TU) Science Design and Analysis of Algorithms (BSc CSIT, CSC314) Question Paper 2080 Nepal
This is the official BSc CSIT (TU) (Science stream) Design and Analysis of Algorithms (BSc CSIT, CSC314) question paper for 2080, 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 2080 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt any TWO questions.
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
Asymptotic notations describe the growth rate of an algorithm's running time as input size .
- Big-O () — upper bound. if there exist constants such that for all . (worst-case guarantee).
- Big-Omega () — lower bound. if for all .
- Big-Theta () — tight bound. if for all ; i.e. is both and .
Master Theorem
For a recurrence of the form with , compare with :
- If for some , then .
- If , then .
- If and the regularity condition holds for , then .
Solving the Recurrences
(i)
Here . Compute .
Since (because ), Case 1 applies:
(ii)
Here . Compute .
Since , Case 2 applies:
Explain the complexity classes P, NP, NP-Hard and NP-Complete with examples. Discuss how a problem is proved to be NP-Complete using polynomial-time reduction.
Complexity Classes
Class P (Polynomial time) — Set of decision problems solvable by a deterministic algorithm in polynomial time . These are the tractable problems. Examples: sorting, shortest path (Dijkstra), matrix multiplication, primality testing.
Class NP (Nondeterministic Polynomial time) — Set of decision problems whose yes-answer (a certificate/witness) can be verified in polynomial time by a deterministic algorithm. Equivalently, solvable in polynomial time by a nondeterministic machine. Examples: SAT, Hamiltonian cycle, subset-sum, vertex cover. Note ; whether is open.
NP-Hard — A problem is NP-Hard if every problem in NP reduces to it in polynomial time. NP-Hard problems are "at least as hard as the hardest problems in NP" but need not themselves be in NP (may not even be decision problems). Example: the optimization version of the Travelling Salesman Problem, Halting problem.
NP-Complete — A problem is NP-Complete if it is (i) in NP and (ii) NP-Hard. These are the hardest problems in NP. If any one NP-Complete problem is solved in polynomial time, then . Examples: CNF-SAT (Cook–Levin), 3-SAT, clique, vertex cover, Hamiltonian cycle.

Proving a Problem NP-Complete by Polynomial-Time Reduction
To prove that a problem is NP-Complete:
- Show — give a polynomial-time verifier: a certificate that can be checked in poly time.
- Show is NP-Hard — pick a known NP-Complete problem and give a polynomial-time reduction , i.e. a poly-time function that maps every instance of to an instance of such that
Because is NP-Complete, every problem in NP reduces to , hence (by transitivity of reduction) to , so is NP-Hard. Together with step 1, is NP-Complete.
Example: 3-SAT Clique is used to prove Clique is NP-Complete.
Write a dynamic programming algorithm for the 0/1 knapsack problem and solve it for items with weights {2, 3, 4, 5} and values {3, 4, 5, 6} with knapsack capacity W = 5.
0/1 Knapsack — Dynamic Programming
Given items with weights and values , and capacity , choose a subset (each item taken fully or not at all) maximizing total value without exceeding .
Let = maximum value using first items with capacity .
Knapsack01(w, v, n, W):
for j = 0 to W: K[0][j] = 0
for i = 1 to n:
for j = 0 to W:
if w[i] > j: K[i][j] = K[i-1][j]
else: K[i][j] = max(K[i-1][j], v[i] + K[i-1][j - w[i]])
return K[n][W]
Time complexity: (pseudo-polynomial).
Solving for weights {2,3,4,5}, values {3,4,5,6}, W = 5
Items (1-indexed): item1 (w=2,v=3), item2 (w=3,v=4), item3 (w=4,v=5), item4 (w=5,v=6).
| i\j | 0 | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 (2,3) | 0 | 0 | 3 | 3 | 3 | 3 |
| 2 (3,4) | 0 | 0 | 3 | 4 | 4 | 7 |
| 3 (4,5) | 0 | 0 | 3 | 4 | 5 | 7 |
| 4 (5,6) | 0 | 0 | 3 | 4 | 5 | 7 |
Key cell .
Maximum value = , achieved by selecting item 1 (w=2, v=3) and item 2 (w=3, v=4), total weight .
Section B: Short Answer Questions
Attempt any EIGHT questions.
Differentiate between Breadth First Search (BFS) and Depth First Search (DFS) with examples and their time complexities.
BFS vs DFS
| Aspect | BFS | DFS |
|---|---|---|
| Traversal order | Level by level (nearest first) | As deep as possible before backtracking |
| Data structure | Queue (FIFO) | Stack (or recursion) |
| Finds | Shortest path (in edges) on unweighted graphs | Path existence; topological sort, cycle detection, SCC |
| Space | (can hold a whole level) | (recursion/stack depth) |
| Completeness | Visits closest vertices first | Explores one branch fully first |
Time complexity (both): with adjacency list; with adjacency matrix.
Example — graph with edges A–B, A–C, B–D, C–D, starting at A:
- BFS order: A, B, C, D (expands A's neighbours first, then theirs).
- DFS order: A, B, D, C (goes A→B→D, backtracks, then C).
Applications: BFS — shortest path in unweighted graphs, peer-to-peer broadcasting; DFS — topological sorting, detecting cycles, finding connected/strongly-connected components.
Solve the recurrence relation T(n) = 2T(n/2) + n using the substitution method and the recursion tree method.
Solving
Recursion Tree Method
At each level the work splits into 2 subproblems of half the size; the non-recursive cost at the root is .
- Level 0: cost .
- Level 1: .
- Level 2: .
- Level : .
The tree has height (since size halves until it reaches 1), so there are levels, each contributing work:
Substitution Method
Guess: , i.e. for suitable and large .
Inductive step: assume it holds for :
This is provided , i.e. . Hence the guess holds, and
(This is exactly the merge-sort recurrence.)
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 profit , where each job takes one unit of time and only one job runs per unit, schedule a subset of jobs to maximize total profit such that each scheduled job finishes within its deadline.
Greedy Strategy
- Sort jobs in decreasing order of profit.
- Maintain a time-slot array of size = max deadline, initially all free.
- For each job (highest profit first), place it in the latest free slot its deadline. If no such slot is free, discard the job.
JobSequencing(jobs):
sort jobs by profit descending
maxDeadline = max(d_i); slot[1..maxDeadline] = free
for each job j:
for t = min(maxDeadline, d_j) downto 1:
if slot[t] is free: assign j to t; break
Time complexity: (or with a disjoint-set / priority-queue optimization).
Example
| Job | A | B | C | D | E |
|---|---|---|---|---|---|
| Deadline | 2 | 1 | 2 | 1 | 3 |
| Profit | 60 | 100 | 20 | 40 | 20 |
Sort by profit: B(100), A(60), D(40), C(20), E(20).
- B (d=1): slot 1 → B.
- A (d=2): slot 2 free → A.
- D (d=1): slot 1 taken → discard.
- C (d=2): slots 1,2 taken → discard.
- E (d=3): slot 3 free → E.
Schedule: slot1=B, slot2=A, slot3=E → jobs {B, A, E}, maximum profit = 100 + 60 + 20 = 180.
Explain the naive string matching algorithm and the Rabin-Karp algorithm with their time complexities.
Naive String Matching
Slide the pattern of length over text of length ; at each of the positions, compare characters one by one.
NaiveMatch(T, P):
n = len(T); m = len(P)
for s = 0 to n - m:
if T[s+1 .. s+m] == P[1 .. m]:
report match at shift s
- Time complexity: worst case (e.g. , ); best case .
- No preprocessing, extra space.
Rabin–Karp Algorithm
Uses a rolling hash to compare the pattern's hash with the hash of each text window in per shift; only on a hash match are characters compared to confirm (handle spurious hits / collisions).
Hash of window using base and prime modulus :
RabinKarp(T, P, d, q):
compute hp = hash(P), ht = hash(T[1..m])
for s = 0 to n - m:
if hp == ht and T[s+1..s+m] == P: report match
update ht to next window using rolling hash
- Time complexity: average / best case ; worst case when many spurious hash collisions occur.
- Preprocessing ; useful for multiple-pattern and 2-D matching.
Summary: Rabin–Karp matches naive's worst case but is typically much faster on average due to constant-time hash comparison.
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)
Precondition: array is sorted. Repeatedly compare the key with the middle element and discard half the array.
BinarySearch(A, low, high, key):
if low > high: return -1 // not found
mid = (low + high) / 2
if A[mid] == key: return mid // found
else if key < A[mid]:
return BinarySearch(A, low, mid-1, key)
else:
return BinarySearch(A, mid+1, high, key)
Recurrence: , which by the master theorem (Case 2, ) gives .
Complexity Analysis
- Best case: — key is the middle element on the first comparison.
- Worst case: — key absent or at the deepest level; array is halved each step.
- Average case: — expected number of comparisons is .
Space: recursive (call stack); iterative.
Explain the randomized quicksort algorithm and analyze its expected time complexity.
Randomized Quicksort
Quicksort partitions the array around a pivot so that elements pivot lie left and elements pivot lie right, then recurses on each side. In randomized quicksort the pivot is chosen uniformly at random (or the array is randomly shuffled), which removes worst-case dependence on the input order.
RandomizedQuicksort(A, p, r):
if p < r:
i = Random(p, r) // random pivot index
swap A[i] with A[r]
q = Partition(A, p, r) // Lomuto/Hoare partition
RandomizedQuicksort(A, p, q-1)
RandomizedQuicksort(A, q+1, r)
Expected Time Complexity
Let be the total number of comparisons. For sorted elements , let if they are ever compared. They are compared iff one of them is the first pivot chosen from the set , so
Then the expected number of comparisons is
Expected running time , independent of input order. The worst case is still (all random pivots extreme), but it occurs with vanishingly small probability. Average extra space for the recursion stack.
Write a greedy algorithm for the fractional knapsack problem and analyze its time complexity.
Fractional Knapsack — Greedy Algorithm
Unlike 0/1 knapsack, here a fraction of an item may be taken. The greedy choice of taking items in decreasing value-to-weight ratio is optimal.
FractionalKnapsack(items, W):
for each item: ratio_i = v_i / w_i
sort items by ratio descending
totalValue = 0; cap = W
for each item i (in sorted order):
if w_i <= cap:
take whole item; totalValue += v_i; cap -= w_i
else:
take fraction cap/w_i; totalValue += v_i * (cap / w_i); break
return totalValue
Time Complexity
- Computing ratios: .
- Sorting by ratio: — dominant term.
- Greedy scan: .
Total: .
Why greedy is optimal: taking the highest density first always fills capacity with the most value per unit weight; since items are divisible, the knapsack is filled exactly to capacity and an exchange argument shows no other selection can do better.
Find the edit distance between the strings "ARTIFICIAL" and "NATURAL" using dynamic programming.
Edit Distance: "ARTIFICIAL" → "NATURAL"
Edit (Levenshtein) distance = minimum insertions, deletions, substitutions to convert one string to another. With of length , of length :
Let ARTIFICIAL (), NATURAL ().
Filling the DP table (rows = ARTIFICIAL, cols = NATURAL):
| "" | N | A | T | U | R | A | L | |
|---|---|---|---|---|---|---|---|---|
| "" | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| A | 1 | 1 | 1 | 2 | 3 | 4 | 5 | 6 |
| R | 2 | 2 | 2 | 2 | 3 | 3 | 4 | 5 |
| T | 3 | 3 | 3 | 2 | 3 | 4 | 4 | 5 |
| I | 4 | 4 | 4 | 3 | 3 | 4 | 5 | 5 |
| F | 5 | 5 | 5 | 4 | 4 | 4 | 5 | 6 |
| I | 6 | 6 | 6 | 5 | 5 | 5 | 5 | 6 |
| C | 7 | 7 | 7 | 6 | 6 | 6 | 6 | 6 |
| I | 8 | 8 | 8 | 7 | 7 | 7 | 7 | 7 |
| A | 9 | 9 | 8 | 8 | 8 | 8 | 7 | 8 |
| L | 10 | 10 | 9 | 9 | 9 | 9 | 8 | 7 |
Edit distance = .
The two strings share the subsequence A, T, R, A, L; aligning these and editing the rest costs 7 operations. Time complexity: .
Write Dijkstra's algorithm to find single-source shortest paths and explain it with an example.
Dijkstra's Single-Source Shortest Path Algorithm
Finds shortest paths from a source to all vertices in a graph with non-negative edge weights, using a greedy approach with a min-priority queue.
Dijkstra(G, w, s):
for each vertex v: dist[v] = INF; prev[v] = NIL
dist[s] = 0
Q = all vertices keyed by dist // min-priority queue
while Q not empty:
u = ExtractMin(Q) // closest unsettled vertex
for each edge (u, v) with weight w(u,v):
if dist[u] + w(u,v) < dist[v]: // relaxation
dist[v] = dist[u] + w(u,v)
prev[v] = u
DecreaseKey(Q, v, dist[v])
return dist, prev
Time complexity: with a binary-heap priority queue; with an array.
Example
Graph: A→B (4), A→C (1), C→B (2), B→D (1), C→D (5). Source = A.
- Start: dist[A]=0, others . Extract A; relax: dist[C]=1, dist[B]=4.
- Extract C (1); relax C→B: ⇒ dist[B]=3; C→D: dist[D]=6.
- Extract B (3); relax B→D: ⇒ dist[D]=4.
- Extract D (4); done.
Final shortest distances from A: A=0, C=1, B=3, D=4. Shortest path to D: A→C→B→D.
Note: Dijkstra fails with negative edge weights; use Bellman–Ford in that case.
Frequently asked questions
- Where can I find the BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) question paper 2080?
- The full BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) 2080 (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) 2080 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) 2080 paper?
- The BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) 2080 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.