Analysis & Design of Algorithm
Analysis & Design of Algorithm
SESSION NOV 24
PROGRAM MCA
SEMSTER III
COURSE CODE AND NAME DCA7104 – ANALYSIS AND DESIGN OF
ALGORITHM
NAME ASHEESH SUNAR
ROLL NO. 2314503637
Ans1(a)
Properties of a Calculation:
This diminishes the pursuit space and makes the arrangement more productive.
Ans.1(b)
Use techniques like the Expert Hypothesis, Replacement Strategy, or Recursion Tree Technique.
Model: Involving Expert Hypothesis for T(n)=2T(n/2)+O(n)T(n) = 2T(n/2) + O(n), the arrangement is
O(nlogn)O(n \log n).
4. Space Intricacy:
Q2.
Bottom Up Example:
Top-Down Example:
Ans 3(a)
Partition and Overcome parts an issue into more modest subproblems, tackles them freely, and blends the
outcomes.
Why Better for Sorting?
1. Efficiency: Calculations like Consolidation Sort and Speedy Sort accomplish O(nlogn)O(n
\log n) time intricacy, which is quicker than credulous techniques like Air pocket Sort (O(n2)O(n^2)).
Ans.3(b)
Insertion Sort Complexity:
o Randomly requested information brings about generally a portion of the components being
moved.
Example:
Ans 4)
The Knapsack problem requires choosing things with greatest complete worth without surpassing a weight
limit WW. The powerful programming approach breaks it into more modest subproblems.
Calculation Steps:
1. Define DP Table:
o Use a 2D exhibit dp[i][j]dp[i][j] where:
3. Recursive Equation:
Exmaple:
• Items: {(wt,val)}={(2,3),(3,4),(4,5),(5,6)}\{(wt, val)\} = \{(2, 3), (3, 4), (4, 5), (5, 6)\},
W=5W = 5.
Space Complexity(nW)O(nW)
ANS.5
The binomial coefficient C(n,k)C(n, k) counts the ways of picking kk things from nn things, determined
utilizing:
C(n,k)=n!k!(n−k)!C(n, k) = \frac{n!}{k!(n-k)!}
Algorithm Steps:
1. Define DP Table:
o Let dp[i][j]dp[i][j] store C(i,j)C(i, j) (binomial coefficient of ii pick jj).
2. Base Cases:
3. Recursive Recipe:
4. Iterative Calculation:
Example:
• C(5,2)=10C(5, 2) = 10.
Time Complexity:O(nk)O(nk)
Space Complexity:O(nk)O(nk)
Ans.6(a)
The Insatiable Decision Property is a quality of streamlining issues where a locally ideal decision at each
step prompts an internationally ideal arrangement.
Key Angles:
o The arrangement can be constructed steadily by pursuing the best decision at each
step.
2. Irrevocable Decisions:
• Pick the following movement that beginnings after the ongoing one finishes.
• Rehash until any longer exercises can't be chosen.
Ans6(b)
A decision tree is a parallel tree used to display the correlations made during an arranging calculation. Every
way from root to leaf addresses a grouping of examinations prompting an arranged stage.
Key Highlights:
1. Internal Nodes:
o Represent examinations between two components A[i]A[i] and A[j]A[j].
2. Leaves:
• A double tree with n!n! leaves should have level ≥log2(n!)\geq \log_2(n!), which is
O(nlogn)O(n \log n).
Example:
For 3 components A,B,CA, B, C:
• The tree brings about arranged orders like ABC,ACB,BAC,… ABC, ACB, BAC, \dots.
This shows that no examination based calculation can sort in under O(nlogn)O(n \log n) time in the most
pessimistic scenario.