0% found this document useful (0 votes)
6 views

Analysis & Design of Algorithm

The document is an internal assignment for the MCA program, focusing on algorithms and their analysis. It covers various topics such as properties of calculations, the Branch and Bound method, recursive algorithm efficiency, sorting algorithms, the Knapsack problem, and the binomial coefficient using dynamic programming. Additionally, it discusses the Insatiable Decision Property and decision trees in sorting algorithms.

Uploaded by

vishalg220
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Analysis & Design of Algorithm

The document is an internal assignment for the MCA program, focusing on algorithms and their analysis. It covers various topics such as properties of calculations, the Branch and Bound method, recursive algorithm efficiency, sorting algorithms, the Knapsack problem, and the binomial coefficient using dynamic programming. Additionally, it discusses the Insatiable Decision Property and decision trees in sorting algorithms.

Uploaded by

vishalg220
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

INTERNAL ASSIGNMENT

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:

• Input: It takes distinct data sources.

• Yield: It produces something like one result.


• Definiteness: Steps are unequivocally characterized.

• Limit: The calculation ought to end after a limited number of steps.

• Adequacy: Each step should be sufficiently basic to be executed.

Branch and Bound Calculation:


Calculation is an enhancement calculation used to take care of combinatorial issues like TSP, 0/1 Rucksack,
and so forth. It deliberately investigates the arrangement space, pruning branches that can't create improved
arrangements than the ongoing best.

Model: Tackling 0/1 Rucksack Issue

Stage 1: Begin with an unfilled arrangement.


Stage 2: At each step, ascertain the bound (maximum constraint) of the ongoing arrangement.

Stage 3: Contrast the bound and the ongoing best arrangement:

Assuming the bound is more terrible, prune that branch.

In any case, investigate further.


Stage 4: Go on until all branches are handled or pruned.

This diminishes the pursuit space and makes the arrangement more productive.

Ans.1(b)

General intend to break down the proficiency of recursive calculations:


The effectiveness of recursive calculations is investigated utilizing the accompanying advances:
1. Write the Repeat Connection:

Define the time intricacy T(n)T(n) as far as more modest subproblems.


Model: Consolidation Sort: T(n)=2T(n/2)+O(n)T(n) = 2T(n/2) + O(n).

2. Solve the Repeat Connection:

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(nlog⁡n)O(n \log n).

3. Base Case Examination:


Determine the time intricacy for the littlest information (e.g., T(1)=O(1)T(1) = O(1)).

4. Space Intricacy:

Include the space utilized by recursive calls (stack space).


This guarantees both existence intricacies are surely known.

Q2.

Feature Bottom-Up Head Top-Down Heap


Construction Construction
Beginning Point Begins from the last non-leaf Begins with a vacant load.
node.
Procedure Adjusts the pile property Inserts components
from base to top. individually and changes.
Efficiency Faster (O(n)O(n)). Slower (O(nlog⁡n)O(n \log
n))
Example Build a maximum store from Incrementally embed
an array. components.
.

Bottom Up Example:

1. Given array: [3, 5, 9, 6, 8].

2. Start heapifying from the last non-leaf hub (index 1).


3. Adjust hubs until the root fulfills the heap property.

Top-Down Example:

1. Insert 3, then 5, then 9, changing the pile after every inclusion.


2. Resulting heap: [9, 5, 3].

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(nlog⁡n)O(n
\log n) time intricacy, which is quicker than credulous techniques like Air pocket Sort (O(n2)O(n^2)).

2. Parallelism: Subproblems can be tackled in equal, decreasing time.

3. Simplicity: It utilizes a particular methodology, making execution more straightforward.


Example: Merge Sort

1. Divide: Split cluster into equal parts.

2. Conquer: Recursively sort every half.


3. Combine: Union the arranged parts.

This diminishes the arranging intricacy fundamentally.

Ans.3(b)
Insertion Sort Complexity:

1. Best Case (O(n)O(n)):

o Array is now arranged.

o Only n−1n-1 examinations are required.


2. Worst Case (O(n2)O(n^2)):

o Array is arranged backward request.

o Each component is analyzed and moved nn times.


3. Average Case (O(n2)O(n^2)):

o Randomly requested information brings about generally a portion of the components being
moved.
Example:

• Array: [5, 3, 2, 1].

• Best Case: [1, 2, 3, 5].

• Assuming the worst possible scenario: [5, 3, 2, 1].

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:

ii: First ii things.


jj: Weight limit of the rucksack.

dp[i][j]dp[i][j]: Greatest worth feasible with these imperatives.

2. Initialize Base Cases:

o dp[0][j]=0dp[0][j] = 0: With 0 things, esteem is 0.


o dp[i][0]=0dp[i][0] = 0: With 0 weight limit, esteem is 0.

3. Recursive Equation:

o For every thing ii:

If wt[i]≤jwt[i] \leq j (thing can fit in the rucksack):


dp[i][j]=max⁡(dp[i−1][j],dp[i−1][j−wt[i]]+val[i])dp[i][j] = \max(dp[i-1][j], dp[i-1][j-wt[i]] + val[i])

In any case: dp[i][j]=dp[i−1][j]dp[i][j] = dp[i-1][j]


4. Iterative Calculation:

o Use settled circles:

External circle for things ii from 1 to nn.

Internal circle for weight jj from 1 to WW.


5. Result:

o dp[n][W]dp[n][W] contains the most extreme worth.

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.

• Result: Maximum Value = 7.


Time Complexity(nW)O(nW)

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)!}

Rather than factorial calculation, utilize dynamic programming for proficiency.

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:

o dp[i][0]=1dp[i][0] = 1: Picking 0 things from ii is 1 way.


o dp[i][i]=1dp[i][i] = 1: Picking ii things from ii is 1 way.

3. Recursive Recipe:

dp[i][j]=dp[i−1][j−1]+dp[i−1][j]dp[i][j] = dp[i-1][j-1] + dp[i-1][j]

o The worth of C(i,j)C(i, j) is the amount of:


Picking j−1j-1 things from i−1i-1, and

Picking jj things from i−1i-1.

4. Iterative Calculation:

o Use settled circles:


External circle for ii from 1 to nn.

Inward circle for jj from 1 to kk.


5. Result:
o dp[n][k]dp[n][k] gives the expected coefficient.

Example:

For n=5, k=2n = 5, k = 2:

• 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:

1. Locally Ideal Foundation:

o The arrangement can be constructed steadily by pursuing the best decision at each
step.

2. Irrevocable Decisions:

o Once a choice is made, it can't be changed later.


Example: Movement Determination Issue

• Sort exercises by finish time.

• Select the principal movement.

• Pick the following movement that beginnings after the ongoing one finishes.
• Rehash until any longer exercises can't be chosen.

Insatiable decision guarantees the greatest number of exercises is 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:

o Represent arranged stages of the exhibit.

3. Height of the Tree:


o Represents the most pessimistic scenario number of correlations.

Sorting Lower Bound:

• For nn components, there are n!n! potential stages.

• A double tree with n!n! leaves should have level ≥log⁡2(n!)\geq \log_2(n!), which is
O(nlog⁡n)O(n \log n).

Example:
For 3 components A,B,CA, B, C:

• Root analyzes A≤BA \leq B.

• Branches look at B≤CB \leq C or C≤AC \leq A.

• 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(nlog⁡n)O(n \log n) time in the most
pessimistic scenario.

You might also like