0% found this document useful (0 votes)
27 views5 pages

Algorithm Analysis and Complexity Overview

The document outlines a comprehensive curriculum covering various topics in algorithm analysis, complexity theory, divide and conquer, greedy algorithms, backtracking, dynamic programming, and NP-completeness. It includes specific tasks such as writing algorithms, analyzing time complexities, and applying various algorithmic techniques to solve problems. Each unit contains multiple questions aimed at assessing understanding and application of algorithmic concepts.

Uploaded by

prashantkori
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views5 pages

Algorithm Analysis and Complexity Overview

The document outlines a comprehensive curriculum covering various topics in algorithm analysis, complexity theory, divide and conquer, greedy algorithms, backtracking, dynamic programming, and NP-completeness. It includes specific tasks such as writing algorithms, analyzing time complexities, and applying various algorithmic techniques to solve problems. Each unit contains multiple questions aimed at assessing understanding and application of algorithmic concepts.

Uploaded by

prashantkori
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Unit1: Introduction to Algorithm Analysis and Complexity Theory

1. Write Difference between asymptotic notions Big O, Omega, and Theta notations provide a real
world analogy to explain when each one is most appropriately .(5M)
2. Explain Amortized Analysis in detail. Discuss its need and various methods used for amortized
analysis. (10M)
3. Solve using the KMP algorithm and Write all intermediate steps, including LPS table construction
and matching process.(5M)

Text: ABABDABACDABABCABAB
Pattern: ABCA

4. Write and apply the Rabin–Karp algorithm to solve the given problem and also
show all hash calculations. (5M)

Text: CCAAEDBA.
Pattern: DBA

Unit 2: Divide and Conquer

1. Write an algorithm to find the maximum and minimum elements in an array X[] of size n using
the least number of comparisons. Also, state its time complexity. (5M)
2. Design a Divide and Conquer algorithm to find the position of a specific element in a sorted array
(Binary Search). Analyze its worst-case time complexity.
3. Design an algorithm for Heap Sort and solve it step by step to sort the array [8, 12, 4, 15, 6, 9,
23,5] in ascending order. (5M min heap 10m Max heap)
4. Sort the following elements using randomized quick sort and trace the steps
55,90,85,99,95,70,68,57,10,23
5. Design an algorithm for Randomized Quick Sort and solve it step by step to sort the array [25,
10, 18, 7, 30, 12, 40, 20] in ascending order.
6. Analyze the time complexity of the Binary Search algorithm. Explain why it is classified as a
Divide and Conquer algorithm. (5M)
7. Apply the Master Theorem to solve the following recurrence relations. Justify your answer by
specifying the values of a, b, and f(n) and identifying the applicable case.
(i) T(n) = 8T(n/2) + n
(ii) T(n) = 4T(n/2) + n
8. Solve the recurrence relation using substitution method
T(n) = { T(1) n=1
aT(n/b)+f(n) n>1 ,where a=5, b=4, and f(n)=cn2

Unit 3: Greedy Algorithms

1. Illustrate the steps in finding the min. cost spanning three for the given graph, using
i) Kruskal’s
ii) Prime's Algorithm

2. Make use of Prim's algorithm to find the minimum cost spanning tree for the given graph starting
from vertex ‘A’. (10M)

3. Apply prim's algorithm to obtain minimum cost spanning tree for the following graph. (10M)

4. Apply Kruskal's algorithm to obtain minimum cost spanning tree for the following graph (10M)

5. Given a set of jobs with their respective deadlines and profits, determine the optimal job sequence
that yields the maximum total profit. Also, calculate the maximum profit earned (10M)
6. Apply Greedy method for the following instance of Fractional Knapsack problem. Given:
Knapsack capacity (M) = 15. (5M)

7. Apply Greedy method for the following instance of Fractional Knapsack problem. Given:
Knapsack capacity (M) = 10. (5M)
Profit = [12,32,40,30,50]
Wt=[4,8,2,6,1]

8. Given five files f1, f2, f3, f4, and f5 with 20, 30, 10, 5, and 30 elements respectively, find the
optimal merge sequence and the minimum total cost using the Optimal Merge Pattern algorithm.

9. Apply Dijkstra’s Algorithm to find the shortest paths from the source vertex ‘A’ to all other
vertices in the given graph. (10M)

10. Write algorithm to find the shortest path for the given graph from source node 'B'.

7. Construct a valid schedule for the following activities using the greedy activity selection strategy.
Your answer should list the selected activities in order.
Activities: (Start, Finish) -> (1, 4), (2, 5), (5, 7), (4, 8), (3, 9), (7, 10), (9, 11)
Unit 4: Backtracking & Dynamic Programming

1. Write the backtracking algorithm for the N-Queens problem and solve [state space tree] the 8-
Queens Problem with time complexity (10M)
2. Outline the backtracking procedure to solve [state space tree] the 4-Queens problem. Provide one
valid solution for a 4x4 board. [5 Marks]

3. Apply Backtracking technique to solve the Sum of Subset Problem for the instance d = 15 and S =
{3, 5, 6,7}
4. Explain the Graph – coloring problem. And draw the state space tree for m= 3 colors n=4 vertices graph.
Discuss the time and space complexity.
5. Write an algorithm to find all m-colouring of graph.
6. Design a solution for the Activity selection problems using the greedy approach. A1 (5,9), A2 (1,2),
A3(3,4), A4(0,6), A5 (3,7),A6 (8,9)
7. Using Dynamic Programming, solve the given instance of 0/1 Knapsack problem. Consider the
capacity of Knapsack (m) = 5.

8. Find the all pairs shortest paths for the given graph using Floyd’s algorithm.

8. Construct a solution for the Longest Common Subsequence (LCS) problem using Dynamic
Programming. Explain the concepts of Optimal Substructure and Overlapping Subproblems in the
context of LCS.
9. Compare and contrast the Memoization (Top-Down) and Tabulation (Bottom-Up) techniques of
Dynamic Programming. List one advantage of each approach.
10. Apply the Dynamic Programming (Tabulation) technique to solve the 0/1 Knapsack problem for
the following instance. Show the complete DP table and trace back to find the selected items.
Weights: [2, 3, 4, 5]
Values: [3, 4, 5, 6]
Knapsack Capacity (W) =8
11. Apply the Floyd-Warshall algorithm to find the all-pairs shortest path for the following graph
Show the initial distance matrix ane the matrices after each iteration (for k=1, 2, 3). [10 Marks]
(Imagine a 3-vertex graph with an adjacency matrix: D° = ([[0, 3, ∞ ], [2, 0, ∞], [∞, 7, 0]])
12. Compare and contrast the Memoization (Top-Down) and Tabulation (Bottom-Up) techniques of
Dynamic Programming. List one advantage of each approach. [5 Marks]
13. Colour the following graph using the minimum number of colours and find its chromatic number

Unit 5: NP- COMPLETENESS

1. Explain the difference between Deterministic and Non-Deterministic Algorithms.


2. Explain the following:
(i) Class P
(ii) Class NP
(iii) NP Complete Problem
(iv) NP Hard Problem.
3. Explain the Genetic algorithm with its working and limitations
4. Explain:
(i) Cook’s theorem
(ii) Hill Climbing algorithm
5. Analyze the Vertex Cover Problem as an example of an Approximation Algorithm.
6. Write Short note on Hill Climbing and Genetic Algorithms, and state one potential application for
each.
7. Analyze the Traveling Salesman Problem (TSP) in the context of its complexity class. Propose a
simple greedy approximation algorithm (like the Nearest Neighbor heuristic) for the Metric TSP.

Common questions

Powered by AI

Big O notation describes the upper bound of an algorithm's runtime, representing the worst-case scenario and performance as input size grows. An analogy could be a speed limit that defines the maximum speed a car can legally travel. Omega notation provides the lower bound, representing the best-case performance, like a minimum speed limit required on a highway. Theta notation gives a tight bound, indicating that an algorithm's runtime asymptotically grows at exactly that rate, much like a narrow lane that restricts both the minimum and maximum operating speed .

The 0/1 Knapsack problem is solved using Dynamic Programming by constructing a table that captures the maximum value obtainable with a fixed weight capacity and subset of items. The solution considers inclusion and exclusion of items for optimal value. Optimal Substructure means an optimal solution can be constructed efficiently from optimal solutions of subproblems, while Overlapping Subproblems indicates that solutions to subproblems are reused multiple times, justifying the tabular approach for efficiency in solving recursive state equations .

The Nearest Neighbor heuristic for the Traveling Salesman Problem (TSP) selects the nearest unvisited city as the next move, a locally optimal choice that extends throughout the tour formation. While this method can yield non-optimal results, it provides a feasible solution quickly. As a greedy approximation, it demonstrates inherent limitations such as non-optimality due to a myopic view, often missing the global optimal tour. However, it's valued for simplicity and speed in metric-stable scenarios like symmetric TSP .

Deterministic algorithms produce the same output for a given input every time with a clearly defined set of operations, making their behavior predictable and verifiable. Non-Deterministic algorithms may offer multiple potential future paths at each step, allowing transitions to a solution without a deterministic method of following paths, often used theoretically to define complexity classes. In complexity, deterministic algorithms define class P (problems solvable in polynomial time), while non-deterministic algorithms relate to class NP (problems verifiable in polynomial time if a solution is given).

Genetic Algorithms (GAs) mimic natural selection principles by evolving a population of candidate solutions over iterations through selection, crossover, and mutation. They are powerful for optimization problems, especially when the search space is large or poorly understood. Yet, GAs face limitations like premature convergence, potentially leading to local optima and computational inefficiency due to population management. Their success leverages genetic diversity and a balance between exploration and exploitation. Applicability includes optimization in complex spaces lacking gradient information .

The KMP algorithm involves constructing the LPS table for pattern 'ABCA', where each LPS[i] represents the longest prefix which is also a suffix for the substring pattern[0:i]. For the text 'ABABDABACDABABCABAB', the LPS table is constructed by iterating over the pattern and updating LPS[i] based on matched characters. The LPS for 'ABCA' is [0, 0, 0, 1]. During matching, the algorithm uses the LPS table to skip unnecessary comparisons, resulting in efficient matching .

The Master Theorem provides a way to solve recurrence relations of the form T(n) = aT(n/b) + f(n) by analysing the parameters a, b, and f(n). For T(n) = 4T(n/2) + n, we have a=4, b=2, and f(n)=n. Comparing n^log_b(a) to f(n) gives log_2(4)=2, which matches f(n)=n, falling into Case 2 of the theorem. This results in a time complexity of Θ(n log n), indicating the algorithm performs similarly to a merge sort .

Class P encompasses decision problems solvable in polynomial time by deterministic algorithms, ensuring the efficiency of solutions. Class NP includes problems verifiable in polynomial time if a solution exists, typically through non-deterministic procedures. NP Complete problems are both in NP and NP Hard, meaning they are as difficult as the hardest problems in NP. NP Hard problems might not even be decidable or verifiable efficiently but they are at least as tough as NP Complete issues, representing the hardest computational challenges .

Amortized analysis considers the average time per operation over a worst-case sequence of operations, providing a more realistic performance measurement than worst-case analysis alone. It is essential when an algorithm has operations that are expensive but infrequent. Methods include Aggregate Analysis, Accounting Method, and Potential Method. Aggregate Analysis determines the total cost across a sequence of operations and averages them; the Accounting Method assigns each operation a cost to cover future operations, and the Potential Method involves a potential function to measure the 'stored energy' of the data structure, explaining the cost distribution over sequences .

Memoization is a top-down approach that involves solving problems recursively and storing the results of subproblems to avoid redundant computations, enhancing efficiency for problems with overlapping subproblems. An advantage is its simplicity when adapting recursive solutions. Tabulation, in contrast, is a bottom-up method that builds a table of solutions iteratively. It often results in better space utilization since it doesn't rely on the function call stack, making it suitable for iterative solutions .

You might also like