113
113
- [ Binary Search Advanced Questions] ( #binary-search-advanced-questions )
114
114
- [ Greedy Algorithm] ( #greedy-algorithm )
115
115
- [ 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 )
116
121
- [ References] ( #references )
117
122
118
123
> 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
1231
1236
## Greedy Algorithm
1232
1237
1233
1238
It is useful for optimization problem.
1234
- Below is the template.
1239
+ Below is the template for Greedy Algorithm .
1235
1240
1236
1241
- Watch [ these videos] ( https://www.youtube.com/watch?v=HzeK7g8cD0Y&list=PLqM7alHXFySESatj68JKWHRVhoJ1BxtLW&t=0s ) to learn greedy algorithm
1237
1242
@@ -1254,6 +1259,47 @@ getOptimal(items, n)
1254
1259
on <a href =" https://codepen.io " >CodePen</a >.</span >
1255
1260
</p >
1256
1261
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
+
1257
1303
## References
1258
1304
1259
1305
- http://btholt.github.io/four-semesters-of-cs/
0 commit comments