Skip to content

Commit b32e09f

Browse files
committed
chore: updated
1 parent 8e0fab0 commit b32e09f

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

‎README.md

+47-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@
113113
- [Binary Search Advanced Questions](#binary-search-advanced-questions)
114114
- [Greedy Algorithm](#greedy-algorithm)
115115
- [Min Coins Problem](#min-coins-problem)
116+
- [Where Greedy Algorithms can be used?](#where-greedy-algorithms-can-be-used)
117+
- [Huffman Coding](#huffman-coding)
118+
- [BST](#bst)
119+
- [For Finding PREDECESSOR](#for-finding-predecessor)
120+
- [For Finding SUCCESSOR](#for-finding-successor)
116121
- [References](#references)
117122

118123
> Coding interview question answers in JavaScript for Facebook, Amazon, Google, Microsoft or any company.
@@ -1231,7 +1236,7 @@ Below problems are lying under optimization problems. Just watch `Book Allocatio
12311236
## Greedy Algorithm
12321237

12331238
It is useful for optimization problem.
1234-
Below is the template.
1239+
Below is the template for Greedy Algorithm.
12351240

12361241
- Watch [these videos](https://www.youtube.com/watch?v=HzeK7g8cD0Y&list=PLqM7alHXFySESatj68JKWHRVhoJ1BxtLW&t=0s) to learn greedy algorithm
12371242

@@ -1254,6 +1259,47 @@ getOptimal(items, n)
12541259
on <a href="https://codepen.io">CodePen</a>.</span>
12551260
</p>
12561261

1262+
Note: Greedy Algorithms may not work always like Longest Path in Binary Tree.
1263+
1264+
![](https://i.imgur.com/utmaXM3.png)
1265+
1266+
### Where Greedy Algorithms can be used?
1267+
1268+
Below are the standard problems solved by Greedy Algorithms.
1269+
1270+
- Activity Selection
1271+
- Fractional Knapsack
1272+
- Job Sequencing
1273+
- Prim's Algorithm
1274+
- Kruskal's algorithm
1275+
- Dijkstra's algorithm
1276+
- Huffman Coding
1277+
- DIEHARD
1278+
- DEFKIN
1279+
- Finding close to optimal solutions for `NP Hard Problem` like `Travelling Salesman Problem`
1280+
1281+
### Huffman Coding
1282+
Merge 2 smallest and make one node.
1283+
Next select 2 smallest and make one node.
1284+
Repeat the merge process
1285+
1286+
Always select 2 minimum one is called as Greedy Algorithm.
1287+
This is called as Optimal Merge Pattern Tree which is Greedy approach
1288+
1289+
![](https://i.imgur.com/eg0KRQ5.png)
1290+
## BST
1291+
1292+
### For Finding PREDECESSOR
1293+
- Take a LEFT then go extreme RIGHT to get predecessor of given node
1294+
- While going right update predecessor
1295+
1296+
### For Finding SUCCESSOR
1297+
- Take a RIGHT then go extreme LEFT to get successor of given node
1298+
- While going left update successor
1299+
1300+
1301+
1302+
12571303
## References
12581304

12591305
- http://btholt.github.io/four-semesters-of-cs/

0 commit comments

Comments
 (0)