Skip to content

Commit ddfcb2b

Browse files
committed
feat:<Greedy Algorithm> greedy algorithm content set
1 parent 1fe6bf3 commit ddfcb2b

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
<p class="text-center mt-5">Coming soon</p>
1+
<h1 class="text-center">Greedy Algorithm</h1>
2+
<div class="mt-md-4 mt-3" [innerHtml]="greedyMetaData.defination"></div>
3+
<div class="mt-md-4 mt-3" [innerHtml]="greedyMetaData.example"></div>
4+
<div class="mt-md-4 mt-3" [innerHtml]="greedyMetaData.properties"></div>
5+
<div class="mt-md-4 mt-3" [innerHtml]="greedyMetaData.components"></div>
6+
<div class="mt-md-4 mt-3" [innerHtml]="greedyMetaData.algorithm"></div>
7+
<div class="mt-md-4 mt-3" [innerHtml]="greedyMetaData.applications"></div>
8+
<div class="mt-md-4 mt-3" [innerHtml]="greedyMetaData.advantage"></div>
9+
<div class="mt-md-4 mt-3" [innerHtml]="greedyMetaData.disadvantage"></div>

src/app/components/Algorithms/greedy/greedy-algorithm/greedy-algorithm.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { greedyMetaData } from 'src/app/core/algorithms/greedy-meta-data';
23

34
@Component({
45
selector: 'app-greedy-algorithm',
56
templateUrl: './greedy-algorithm.component.html',
67
styleUrls: ['./greedy-algorithm.component.css']
78
})
89
export class GreedyAlgorithmComponent implements OnInit {
9-
10+
greedyMetaData = greedyMetaData;
1011
constructor() { }
1112

1213
ngOnInit(): void {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { Helper } from "src/app/helper/helper"
2+
3+
const greedyData = {
4+
defination: `A greedy algorithm is an approach for solving a problem by selecting the best option available at the moment.
5+
It doesn't worry whether the current best result will bring the overall optimal result. <br>
6+
The algorithm never reverses the earlier decision even if the choice is wrong. It works in a top-down approach.
7+
<br>
8+
This algorithm may not produce the best result for all the problems. It's because it always goes for the local best
9+
choice to produce the global best result.
10+
`,
11+
example: 'assets/ds-image/greedy.jpg',
12+
properties:[
13+
`<b>Greedy Choice Property:</b> If an optimal solution to the problem can be found by choosing the best choice at
14+
each step without reconsidering the previous steps once chosen, the problem can be solved using a greedy approach.
15+
This property is called greedy choice property.`,
16+
`<b>Optimal Substructure:</b> If the optimal overall solution to the problem corresponds to the optimal solution to
17+
its subproblems, then the problem can be solved using a greedy approach. This property is called optimal substructure.`
18+
],
19+
components:[
20+
`<b>Candidate set:</b> A solution that is created from the set is known as a candidate set.`,
21+
`<b>Selection function:</b> This function is used to choose the candidate or subset which can be added in the solution.`,
22+
`<b>Feasibility function:</b> A function that is used to determine whether the candidate or subset can be used to contribute
23+
to the solution or not.`,
24+
`<b>Objective function:</b> A function is used to assign the value to the solution or the partial solution.`,
25+
`<b>Solution function:</b> This function is used to intimate whether the complete function has been reached or not.`,
26+
],
27+
algorithm:[
28+
`To begin with, the solution set (containing answers) is empty.`,
29+
`At each step, an item is added to the solution set until a solution is reached.`,
30+
`If the solution set is feasible, the current item is kept.`,
31+
`Else, the item is rejected and never considered again.`
32+
],
33+
applications:[
34+
`Selection Sort`,
35+
`Fractional knapsack Problem`,
36+
`Minimum Spanning Tree(Prim's, Kruskal's,)`,
37+
`Single-Source Shortest Path Problem`,
38+
`Job Scheduling Problem`,
39+
`Huffman Coding`,
40+
`Ford-Fulkerson Algorithm`
41+
],
42+
advantages: [
43+
`The algorithm is easier to describe.`,
44+
`This algorithm can perform better than other algorithms (but, not in all cases).`
45+
],
46+
disadvantage: [
47+
`As mentioned earlier, the greedy algorithm doesn't always produce the optimal solution.
48+
This is the major disadvantage of the algorithm`
49+
]
50+
}
51+
52+
export const greedyMetaData = {
53+
defination: Helper.setHeader(greedyData.defination),
54+
example: Helper.setExampleImage('Greedy Approach', greedyData.example),
55+
properties: Helper.setListwithTitleHtml('Properties of Greedy Algorithm', greedyData.properties),
56+
components: Helper.setListwithTitleHtml('Components of Greedy Algorithm', greedyData.components),
57+
algorithm: Helper.setListwithTitleHtml('Greedy Algorithm', greedyData.algorithm),
58+
applications: Helper.setListwithTitleHtml('Applications of Greedy Algorithm', greedyData.applications),
59+
advantage: Helper.setListwithTitleHtml('Advantages of Greedy Algorithm', greedyData.advantages),
60+
disadvantage: Helper.setListwithTitleHtml('Disadvantages of Greedy Algorithm', greedyData.disadvantage),
61+
62+
}

0 commit comments

Comments
 (0)