B.
TECH DEGREE EXAMINATIONS –MAY 2025
10211CS202- DESIGN AND ANALYSIS OF ALGORITHMS
(Regulations VTR UGE 2021)
Maximum: 60 Marks Duration: Three Hours
Cognitive (K) Levels
K1-Remenber, K2-Understand, K3-Apply, K4-Analyze, K5-Evaluate, K6-Create
PART-A (10 X 2 = 20 Marks) [K1 and / or K2 Level]
Answer ALL Questions. Each question carries 2 Marks
Scheme of Evaluation
1.
Input two positive integers: a and b
Repeat the following steps until b becomes 0:
Calculate the remainder: r = a % b
Replace a with b
Replace b with r
When b becomes 0, the value of a is the GCD
Output the GCD
2. Time complexity: Time complexity measures the amount of time an algorithm takes to run as
a function of input size.
Space complexity: Space complexity measures the amount of memory or space an algorithm
uses as a function of input size.
3. Divide: Break the problem into smaller subproblems of the same type.
Conquer: Solve the subproblems recursively. If subproblems are small enough, solve
them directly.
Combine: Merge the solutions of the subproblems to get the final result.
4. Algorithm BinarySearch(arr, low, high, key)
1. while low ≤ high do
2. mid ← (low + high) / 2
3. if arr[mid] = key then
4. return mid
5. else if arr[mid] < key then
6. low ← mid + 1
7. else
8. high ← mid - 1
9. return -1 // Element not found
Time Complexity: O(log n)
5. Dynamic Programming
Definition:
Dynamic Programming (DP) is a technique for solving complex problems by breaking them
down into simpler overlapping subproblems, solving each subproblem only once, and storing
their solutions – usually using memoization or tabulation.
Key Features:
Optimal substructure
Overlapping subproblems
Example Problems:
Fibonacci series, 0/1 Knapsack
6.Bi-connected Component
Definition:
A bi-connected component (also called a 2-connected component) of an undirected graph is a
maximal set of edges such that any two vertices in the set remain connected after removing any
one vertex (no articulation point in the component).
Example:
Graph with vertices A, B, C, D and edges:
(A–B), (B–C), (C–A), (B–D)
7: Define Backtracking
Definition:
Backtracking is a general algorithmic technique that involves searching through all possible
solution of a problem and back track as soon as it is determined it cannot lead to a valid
solution.
Key Idea: Build a solution incrementally, and backtrack when a constraint is violated.
Applications: N-Queens, Graph Coloring, Sudoku Solver, Hamiltonian Cycle, Subset Sum.
8: How Backtracking is used to implement Graph Coloring?
Explanation:
Goal: Assign colors to the vertices of a graph such that no two adjacent vertices have the
same color using at most m colors.
Backtracking Approach:
1. Start with the first vertex.
2. Assign a color that does not violate constraints (i.e., adjacent vertices have
different colors).
3. Move to the next vertex.
4. If no color can be assigned, backtrack to the previous vertex and try a different
color.
Key Constraint: color[i] ≠ color[j] if vertex i is adjacent to vertex j.
9: What is a Polynomial Problem?
Definition:
A polynomial problem is a computational problem that can be solved in polynomial time, i.e.,
the time required to solve the problem is bounded by a polynomial expression in the size of the
input.
Time Complexity: O(n), O(n²), O(n³), etc.
Examples:
Binary Search: O(log n)
Bubble Sort: O(n²)
Dijkstra’s Algorithm: O(V²)
Matrix Multiplication: O(n³)
Class of such problems: Belongs to the P class (deterministically solvable in polynomial time).
10: Distinguish NP and NP-Complete
Aspect NP (Non-deterministic Polynomial)NP-Complete
Class of problems for which a Subset of NP; solution can be verified and any
Definition solution can be verified in NP problem can be reduced to it in polynomial
polynomial time time
Hardest problems in NP; if any NP-Complete
May or may not be solved in
Solvability problem is solved in P time, all NP problems
polynomial time
can be
SAT, 3-SAT, Traveling Salesman Decision
Example Hamiltonian Path, Subset Sum
Problem
Relation All NP-Complete problems are in NP Not all NP problems are NP-Complete
Part B
11(a): Explain the Asymptotic Notations Big-O (O), Big-Omega (Ω), and Theta (θ) with
Example
1. Big-O Notation (O) – Upper Bound
Describes the worst-case time complexity.
It gives the maximum amount of time an algorithm can take.
Definition:
A function f(n) is O(g(n)) if there exist constants c > 0 and n₀ ≥ 0 such that:
f(n) ≤ c * g(n) for all n ≥ n₀.
Example:
For f(n) = 3n + 5, it is O(n) because 3n + 5 ≤ 4n for all n ≥ 5.
2. Big-Omega Notation (Ω) – Lower Bound
Describes the best-case time complexity.
It provides the minimum time the algorithm takes.
Definition:
A function f(n) is Ω(g(n)) if there exist constants c > 0 and n₀ ≥ 0 such that:
f(n) ≥ c * g(n) for all n ≥ n₀.
Example:
For f(n) = 3n + 5, it is Ω(n) because 3n + 5 ≥ 3n for all n.
3. Theta Notation (θ) – Tight Bound
Describes the exact (average) time complexity.
It gives both the upper and lower bound.
Definition:
A function f(n) is θ(g(n)) if there exist constants c₁, c₂ > 0 and n₀ ≥ 0 such that:
c₁ * g(n) ≤ f(n) ≤ c₂ * g(n) for all n ≥ n₀.
Example:
For f(n) = 3n + 5, it is θ(n) because it's bounded both above and below by linear
functions.
11(b): Solve the Recurrence Relation
Given:
Using Recursion Tree / Iteration Method
Let’s expand the recurrence:
So
Next:
After k steps,
12)a)Describe Exhaustive Search in detail
Exhaustive Search (also called brute force) is a method of solving problems by checking
all possible candidates for the solution and selecting the best one.
Used for optimization and decision problems.
Example Applications: Traveling Salesman Problem (TSP), Knapsack Problem,etc.
Advantages: Guarantees finding the optimal solution.
Disadvantages: Highly inefficient for large inputs due to exponential time complexity.
Q12(b): Summarize the following
(i) Divide and Conquer Technique
Strategy that recursively splits a problem into smaller parts, solves each part, and
combines them.
Improves efficiency for problems with overlapping substructures.
Examples: Merge Sort, Quick Sort, Binary Search, Matrix Multiplication (Strassen's).
Time Complexity: Depends on problem. E.g., Merge Sort: O(n log n)
(ii) Heap Sort
A comparison-based sorting algorithm using a binary heap (max-heap or min-heap).
Steps:
1. Build a heap from the input data.
2. Repeatedly extract the maximum (or minimum) and adjust the heap.
Time Complexity: O(n log n)
Space Complexity: O(1) (in-place sorting)
Not stable, but very efficient for large datasets.
13(a): Illustrate Travelling Salesperson Problem (TSP) algorithm with example
TSP is a classic optimization problem:
"Given a list of cities and distances between them, find the shortest possible route that visits each
city exactly once and returns to the starting city."
Approach:
Exhaustive Search: Try all permutations (O(n!))
Dynamic Programming (Held-Karp): O(n²·2ⁿ)
Approximation / Heuristics: e.g., Nearest Neighbor
Example:
Cities: A, B, C, D
Distance matrix:
A B C D
A 0 10 15 20
B 10 0 35 25
C 15 35 0 30
D 20 25 30 0
Try paths like A → B → C → D → A and compute the cost.
Optimal tour: A → B → D → C → A with cost = 80 (example result)
13(b): Describe Graph Traversal Algorithm with Example
Graph traversal is the process of visiting all the nodes in a graph.
Two common methods:
1. Breadth-First Search (BFS):
o Uses a queue
o Visits nodes level by level
o Best for finding shortest path in unweighted graphs
2. Depth-First Search (DFS):
o Uses a stack (or recursion)
o Explores as far as possible before backtracking
Example:
14(a): Develop an algorithm to find out Hamiltonian Cycle in a graph. Explain with
example
A Hamiltonian cycle is a path in a graph that visits each vertex exactly once and returns to the
starting vertex.
Algorithm (Backtracking):
Algorithm HamiltonianCycle(Graph G, Path[], pos):
1. if pos == V and there is an edge from Path[pos-1] to Path[0]:
return True
2. for each vertex v in G:
if v is adjacent to Path[pos-1] and v not in Path:
Path[pos] = v
if HamiltonianCycle(G, Path, pos + 1):
return True
Path[pos] = -1 // Backtrack
3. return False
Example:
14(b): Explain 8-Queen's Algorithm with Example
Problem:
Place 8 queens on an 8×8 chessboard such that no two queens attack each other (no two queens
share same row, column, or diagonal).
Backtracking Algorithm:
1. Start from row 0.
2. Try placing a queen in each column of the current row.
3. For each placement, check if it’s safe (no conflicts).
4. If safe, recursively place queen in the next row.
5. If no safe column found, backtrack to the previous row.
Key Condition for Safety:
No other queen in the same column
No other queen in the same / or \ diagonal
Number of total solutions for 8-Queens: 92
15(a): Explain NP Problems with Example
Definition:
NP (Nondeterministic Polynomial time) problems are decision problems where a solution, once
guessed, can be verified in polynomial time.
i.e., Checking is easy, solving may not be.
Example:
Subset Sum Problem:
Given a set of integers, is there a subset whose sum is equal to a given number?
o Checking a subset's sum = target → polynomial time.
o Finding such a subset → possibly exponential time.
P ⊆ NP, but whether P = NP is an open problem.
15(b): Explain in detail the Maximum Matching in Bipartite Graph with Example
Definition:
A matching in a bipartite graph is a set of edges such that no two edges share a common vertex.
A maximum matching is a matching that contains the largest possible number of edges.
Approach:
Use Hungarian Algorithm (for weighted matching) or Hopcroft–Karp Algorithm (for
unweighted).
In unweighted graphs, a matching is maximum if no augmenting path can be found.
Example:
Let the bipartite graph have:
Set U = {u1, u2, u3}
Set V = {v1, v2, v3}
Edges:
u1 – v1
u1 – v2
u2 – v2
u3 – v3
One possible maximum matching:
u1 – v1
u2 – v2
u3 – v3
Matching size = 3 (maximum, as all vertices are matched).
Applications:
Job assignment
Stable marriages
Network flows
Often solved using Ford–Fulkerson algorithm by converting the bipartite graph into a flow
network.