0% found this document useful (0 votes)
52 views2 pages

Design and Analysis of Algorithm

The document contains an algorithm named Greedy that takes an array a containing n inputs and uses a greedy approach to find a solution. The Greedy algorithm iterates from 1 to n, selects an input X from a, checks if adding X to the solution is feasible, and if so unions X with the solution. The document also explains key parts of the greedy method for algorithm design including the select, feasible, and union functions.

Uploaded by

Abhinav arora
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)
52 views2 pages

Design and Analysis of Algorithm

The document contains an algorithm named Greedy that takes an array a containing n inputs and uses a greedy approach to find a solution. The Greedy algorithm iterates from 1 to n, selects an input X from a, checks if adding X to the solution is feasible, and if so unions X with the solution. The document also explains key parts of the greedy method for algorithm design including the select, feasible, and union functions.

Uploaded by

Abhinav arora
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
You are on page 1/ 2

DESIGN AND ANALYSIS OF ALGORITHM

NAME – ABHINAV ARORA COMP – 1 ROLL NO. – 09

REVIEW OF THE DAY – 30TH MARCH

Q. Write algorithm greedy (a, n) where a[1:n] contains n inputs and with respect to
this explain Greedy method of algorithm design.

A. Algorithm for Greedy (a, n) where a[1:n] contains n inputs


Algorithm Greedy(a, n)
//a[1:n] contains the n inputs
{
Solution := 0 : for
:= 1 to n do
{
X := Select(a);
If feasible (Solution X) then
Solution : = Union (solution X):
}
Return Solution:
Greedy method of algorithm design
}

Selection -> Function that selects an input from a[] and removes it. The selected
input’s value is assigned to X.
Feasible -> Boolean valued function that determines whether x can be included
into the solution vector.
Union -> Function that combines X with solution
and updates the objective function

You might also like