Professional Documents
Culture Documents
AOA 2021 Solution
AOA 2021 Solution
Ans .
�(�)=��(��)+�(�)T(n)=aT(bn )+f(n)
Ques 2 . What is the difference between Dynamic Programming and Divide and
Conquer Mechanism?
Ans. Dynamic Programming (DP) and Divide and Conquer (D&C) are both
algorithmic paradigms that solve problems by breaking them down into
subproblems. However, there are key differences in their mechanisms and
approaches:
Divide and Conquer:
Subproblem Independence:
D&C breaks down a problem into smaller subproblems.
The subproblems are solved independently.
The solutions of subproblems are combined to solve the original problem.
Recursion:
D&C typically involves recursive algorithms.
The problem is divided into smaller instances of the same problem until base
cases are reached.
Overlapping Subproblems:
D&C may not handle overlapping subproblems efficiently.
If the same subproblem is solved multiple times, D&C might not optimize by
storing and reusing previous solutions.
Example Algorithm:
QuickSort and MergeSort are classic examples of Divide and Conquer
algorithms.
Binary search is another example.
Dynamic Programming:
Optimal Substructure:
DP requires the problem to have optimal substructure.
The optimal solution to the problem can be constructed from optimal
solutions of its subproblems.
Memoization/Tabulation:
DP optimizes by storing solutions to subproblems and reusing them when
needed.
Memoization involves storing solutions in a table for future reference.
Tabulation involves building a table of solutions bottom-up.
Bottom-Up Approach:
DP often uses a bottom-up approach to solve the problem.
It starts from the simplest subproblems and builds solutions for larger
subproblems.
Overlapping Subproblems:
DP explicitly addresses overlapping subproblems.
The solutions to subproblems are stored in a data structure (like a table) and
reused when needed.
Example Algorithms:
Fibonacci series calculation using memoization or tabulation.
Shortest Path algorithms like Floyd-Warshall.
Longest Common Subsequence (LCS) problem.
Ans.
Ques 8. Give a recurrcncc for merger sort algorithm and solvc it.
Ans.
Answer
Ans. Backtracking is a general algorithm for finding all (or some) solutions to
computational problems, particularly constraint satisfaction problems. When using a
backtracking approach, certain constraints and components are essential for the method
to work effectively. Here are the key constraints and requirements for a Backtracking
method:
• Decision Space:
• The problem should be decomposable into a set of decisions. Each decision
represents a choice or an option that contributes to the solution.
• Feasibility Function:
• There should be a feasibility function that checks whether a partial solution can
be extended to a complete solution. This function helps in pruning the search
space when a partial solution cannot lead to a valid solution.
• Objective Function (optional):
• For optimization problems, an objective function is used to evaluate the quality
of a solution. The backtracking algorithm may aim to find the optimal solution,
and the objective function guides the search.
• Partial Solution:
• The algorithm incrementally builds a partial solution by making decisions and
backtracks when it determines that the partial solution cannot be extended to a
valid solution.
• Backtracking Mechanism:
• The algorithm needs a mechanism to backtrack when it encounters a dead-end
or determines that the current path will not lead to a valid solution. This typically
involves undoing the last decision and exploring other options.
• Proper Ordering of Decisions:
Part B
Ques 1.
Answer.
Ques 2 What is the usc of prefix function in KMP string matching algorithm? Explain
Wilh example.
Ans.
Answer
Ans.
Answer
Ques 4 . Write short notes on the following:(a) Quadratic assignment problem
Ans.
Answer
Ques 5 . Explain the Las Vegas and Monte Carlo Algorithm with example.
Ans. Las Vegas Algorithm:
A Las Vegas algorithm is a type of randomized algorithm that always produces the
correct result, but its running time is allowed to be probabilistic. The key characteristic is
that it always gives the correct answer when it terminates, but the time it takes to
terminate may vary based on random choices. If the algorithm runs for a random
amount of time, it may be faster or slower on different runs.
The Quicksort algorithm can be turned into a Las Vegas algorithm by randomly
choosing a pivot during the partitioning step. This ensures that the expected running
time is good, but the actual running time may vary depending on the specific random
choices made.
A Monte Carlo algorithm is a randomized algorithm that may produce incorrect results
with some small probability. The key characteristic is that it has a probabilistic element,
and its correctness is not guaranteed. However, it is designed in such a way that the
probability of producing an incorrect result is very low.
The Miller-Rabin primality test is a Monte Carlo algorithm for determining whether a
given number is likely to be a prime number. It may occasionally produce false positives
(indicating a composite number as prime), but the probability of this happening can be
made arbitrarily small by adjusting the number of random tests.
Ques 6 Solve thc following recurrence relations and find their complcxitics using master
method-