BSc CSIT (TU) Science Design and Analysis of Algorithms (BSc CSIT, CSC314) Question Paper 2079 Nepal
This is the official BSc CSIT (TU) (Science stream) Design and Analysis of Algorithms (BSc CSIT, CSC314) 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 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 2079 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt any TWO questions.
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 minimum among all spanning trees.
Kruskal's Algorithm
Kruskal's algorithm is a greedy algorithm. It repeatedly picks the smallest-weight edge that does not form a cycle, using a disjoint-set (Union-Find) structure to detect cycles.
KRUSKAL(G):
A = {} // edges of MST
for each vertex v in V: MAKE-SET(v)
sort edges of E in non-decreasing order of weight
for each edge (u,v) in sorted order:
if FIND-SET(u) != FIND-SET(v): // adding edge does not form a cycle
A = A union {(u,v)}
UNION(u, v)
return A
Example
Consider a graph with vertices and edges: .
Process edges in increasing order:
| Edge | Weight | Action |
|---|---|---|
| AB | 1 | Add (no cycle) |
| BC | 2 | Add (no cycle) |
| AC | 3 | Reject (A,C already connected) |
| CD | 4 | Add (no cycle) |
| BD | 5 | Reject (B,D connected) |
| DE | 6 | Add (no cycle) |
MST edges = , total weight , with edges.
Complexity Analysis
- Sorting the edges: .
- MAKE-SET and at most FIND/UNION operations with union by rank + path compression: , nearly linear.
- Total: (since , ).
Correctness follows from the greedy cut property: the lightest edge crossing any cut is safe to add to the MST.
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 be non-negative functions.
- Big-O (upper bound): if there exist constants such that for all . (worst-case growth)
- Big-Omega (lower bound): if with for all . (best-case / lower growth)
- Big-Theta (tight bound): if and , i.e. with .
Master Theorem
For a recurrence with , let . Compare with :
- If for some : .
- If : .
- If and the regularity condition holds for : .
(a)
Here . So .
Since (because ), Case 1 applies:
(b)
Here . So .
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
- P (Polynomial time): Decision problems solvable by a deterministic algorithm in polynomial time . Examples: sorting, shortest path (Dijkstra), checking primality.
- NP (Nondeterministic Polynomial): Decision problems whose yes-answers can be verified in polynomial time given a certificate. Equivalently, solvable by a nondeterministic machine in polynomial time. Examples: SAT, Hamiltonian cycle, subset-sum. Note .
- 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 be in NP (and need not be decision problems). Example: the optimization Travelling Salesman Problem, the Halting problem.
- NP-Complete: A problem that is both in NP and NP-Hard. These are the hardest problems in NP. Examples: SAT (Cook–Levin theorem), 3-SAT, vertex cover, clique, Hamiltonian cycle.
Relationship: , . Whether is open.
Proving NP-Completeness via Polynomial-Time Reduction
To prove a problem is NP-Complete:
- Show : give a polynomial-time verifier that checks a proposed certificate (solution).
- Show is NP-Hard: pick a known NP-Complete problem and construct a polynomial-time reduction — a transformation that maps any instance of to an instance of in polynomial time such that
- Since is NP-Complete, every NP problem reduces to and hence (by transitivity of reductions) to . Therefore is NP-Hard, and combined with step 1, is NP-Complete.
Example: 3-SAT Clique shows Clique is NP-Hard; together with Clique this proves Clique is NP-Complete.
Section B: Short Answer Questions
Attempt any EIGHT questions.
What are approximation algorithms? Explain the approximation algorithm for the vertex cover problem.
Approximation Algorithms
For NP-Hard optimization problems exact optimal solutions cannot (assuming ) be found in polynomial time. An approximation algorithm runs in polynomial time and returns a solution provably close to optimal. For a minimization problem it has approximation ratio if for every input , where is the cost returned and the optimal cost.
Approximation Algorithm for Vertex Cover
A vertex cover is a set of vertices covering every edge. Finding a minimum vertex cover is NP-Hard. A simple 2-approximation:
APPROX-VERTEX-COVER(G):
C = {}
E' = edges of G
while E' is not empty:
pick any edge (u, v) from E'
C = C union {u, v}
remove from E' all edges incident to u or v
return C
Why ratio 2: 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 matched edge, so . The algorithm adds both endpoints, so . Hence it is a 2-approximation, running in time.
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 systematic technique for solving optimization problems by exploring a state-space tree. It has two key operations:
- Branching: split a problem into smaller subproblems (children nodes).
- Bounding: compute a bound (lower bound for minimization) on the best solution obtainable in each subtree. If a node's bound is worse than the best solution found so far (the incumbent), the whole subtree is pruned, avoiding unnecessary exploration.
Unlike pure backtracking, B&B uses bounds to prune, and can use best-first / least-cost selection of the next node to expand.
Solving the Travelling Salesman Problem (TSP)
TSP asks for a minimum-cost tour visiting every city exactly once and returning to start.
- State-space tree: each node represents a partial path; branching extends the path to an unvisited city.
- Cost / lower bound: for each node compute a lower bound, commonly using the reduced cost matrix — reduce each row and column by its minimum; the sum of reductions plus the parent bound gives the node's lower bound on the completed tour cost.
- Search: expand the live node with the smallest lower bound (least-cost B&B). Maintain the best complete tour found (incumbent / upper bound).
- Pruning: discard any node whose lower bound current best tour cost.
- Continue until the least-cost live node is a complete tour; that tour is optimal.
B&B does not improve worst-case complexity ( in the worst case) but in practice prunes large portions of the search space, making moderate instances tractable.
Differentiate between Breadth First Search (BFS) and Depth First Search (DFS) with examples and their time complexities.
BFS vs DFS
Both traverse a graph visiting every reachable vertex once.
- BFS explores level by level from a source, using a queue (FIFO). It first visits all neighbours, then their neighbours, finding shortest paths in unweighted graphs.
- DFS explores as deep as possible along a branch before backtracking, using a stack (LIFO) or recursion. Used for topological sort, cycle detection, connected components.
| Feature | BFS | DFS |
|---|---|---|
| Data structure | Queue (FIFO) | Stack / recursion (LIFO) |
| Strategy | Level by level | Deep then backtrack |
| Shortest path (unweighted) | Yes | No |
| Space | (queue holds a level) | (recursion stack) |
| Applications | Shortest path, level order | Topological sort, cycle detection, SCC |
Example
Graph: –, –, –, –. Starting at :
- BFS order: (visit 's neighbours first, then ).
- DFS order: (go deep , backtrack, then ).
Time Complexity
Using an adjacency list, both run in . With an adjacency matrix both are .
Solve the recurrence relation T(n) = 2T(n/2) + n using the substitution method and the recursion tree method.
Recurrence
This is the merge-sort recurrence. We show .
Substitution Method
Guess: , i.e. for some .
Assume it holds for : . Then
This is provided , i.e. . So the guess holds and . A symmetric argument gives , hence .
Recursion Tree Method
At the root the cost is . It splits into 2 subproblems of size , each costing , so level-1 cost . In general at level there are nodes each of size , contributing .
- Cost per level: (constant across levels).
- Number of levels: the size shrinks to 1 after splits, so there are levels.
Total cost .
Result: (confirmed by both methods; also matches Master Theorem Case 2 with ).
Explain the job sequencing with deadlines problem and solve it using the greedy approach for a given set of jobs.
Job Sequencing with Deadlines
Given jobs, each with a deadline and profit , where each job takes one unit of time and only one job runs at a time. A job earns its profit only if completed by its deadline. Goal: schedule a subset of jobs to maximize total profit.
Greedy Approach
- Sort jobs in decreasing order of profit.
- Find the maximum deadline ; create time slots, all free.
- For each job (highest profit first), place it in the latest free slot its deadline. If no free slot exists, skip the job.
- The filled slots give the schedule.
JOB-SEQUENCING(jobs):
sort jobs by profit descending
D = max deadline; slot[1..D] = free
for each job j:
for t = min(D, j.deadline) down to 1:
if slot[t] is free:
slot[t] = j; break
return filled slots
Example
| Job | A | B | C | D | E |
|---|---|---|---|---|---|
| Profit | 20 | 15 | 10 | 5 | 1 |
| Deadline | 2 | 2 | 1 | 3 | 3 |
Sorted by profit: A,B,C,D,E. Max deadline , slots .
- A (d=2) → slot 2:
- B (d=2) → slot 1 (2 taken):
- C (d=1) → slot 1 taken, skip.
- D (d=3) → slot 3:
- E (d=3) → all taken, skip.
Schedule: B → A → D, maximum profit .
Complexity: for sorting plus for slot assignment (improvable to near with a disjoint-set structure).
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 text of length , the naive algorithm slides over every position and checks character by character.
NAIVE-MATCH(T, P):
n = length(T); m = length(P)
for s = 0 to n - m:
if T[s+1 .. s+m] == P[1 .. m]:
report match at shift s
- Time: in the worst case (e.g. , ). No preprocessing.
Rabin–Karp Algorithm
Rabin–Karp uses hashing. It computes a hash of the pattern and of each length- window of the text; only when hashes match does it compare characters (to rule out spurious hits).
- Compute hash of the pattern.
- Compute hash of .
- Slide the window: update the hash in using a rolling hash
where is the alphabet size and a large prime. 4. When , verify the actual characters to confirm.
- Time: Preprocessing ; matching on average (with a good hash and few collisions), but in the worst case when many spurious hash collisions force full comparisons.
Summary: both report all occurrences; Rabin–Karp is typically faster in practice and naturally extends to multi-pattern and 2-D matching.
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.
BINARY-SEARCH(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 BINARY-SEARCH(A, low, mid - 1, x) // search left half
else:
return BINARY-SEARCH(A, mid + 1, high, x) // search right half
The recurrence is , which by the Master Theorem (Case 2 with ) gives .
Complexity Analysis
- Best case: key is the middle element on the first comparison → .
- Worst case: key absent or at the deepest level; the array halves each step, so comparisons → .
- Average case: also (the search tree has depth , so expected comparisons ).
- Space: for the recursion stack, or if written iteratively.
Explain the randomized quicksort algorithm and analyze its expected time complexity.
Randomized Quicksort
Quicksort sorts by choosing a pivot, partitioning the array so that elements smaller than the pivot go left and larger go right, then recursively sorting the two parts. Standard quicksort degrades to when the pivot is consistently the smallest/largest (e.g. already-sorted input).
Randomized quicksort avoids this by choosing the pivot uniformly at random from the subarray, so no particular input triggers worst-case behaviour.
RANDOMIZED-QUICKSORT(A, p, r):
if p < r:
i = RANDOM(p, r) // random index
swap A[i] with A[r] // random pivot
q = PARTITION(A, p, r) // O(n) partition around pivot
RANDOMIZED-QUICKSORT(A, p, q - 1)
RANDOMIZED-QUICKSORT(A, q + 1, r)
Expected Time Complexity
Let be the total number of comparisons. Define indicator if elements of ranks and are ever compared. Two elements are compared iff one of them is chosen as pivot before any element ranked between them, which happens with probability . Thus
Therefore the expected running time is , independent of the input ordering. The worst case is still but occurs only with negligibly small probability.
Write a greedy algorithm for the fractional knapsack problem and analyze its time complexity.
Fractional Knapsack Problem
Given items each with weight and value , and a knapsack capacity , choose fractions of each item to maximize subject to . Because items can be divided, a greedy strategy by value-to-weight ratio gives the optimal solution.
Greedy Algorithm
- Compute the ratio for each item.
- Sort items in decreasing order of .
- Take items fully in that order until the next item does not fit; take a fraction of that item to fill the remaining capacity exactly.
FRACTIONAL-KNAPSACK(items, W):
sort items by (v_i / w_i) descending
total = 0; cap = W
for each item i in sorted order:
if w_i <= cap:
take whole item; total += v_i; cap -= w_i
else:
total += v_i * (cap / w_i) // take fraction
break
return total
Optimality: the exchange argument shows replacing any part of a lower-ratio item with a higher-ratio one never decreases value, so the greedy choice is optimal.
Time Complexity
- Sorting by ratio: .
- Single greedy pass: .
- Total: , dominated by sorting.
Frequently asked questions
- Where can I find the BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) question paper 2079?
- The full BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) 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 Design and Analysis of Algorithms (BSc CSIT, CSC314) 2079 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) 2079 paper?
- The BSc CSIT (TU) Design and Analysis of Algorithms (BSc CSIT, CSC314) 2079 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.