You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20
Original file line number
Diff line number
Diff line change
@@ -115,6 +115,13 @@ remainder.
115
115
Then we take the remainder and quotient from bottom to top and assign them alphabets corresponding to their
116
116
values.
117
117
118
+
### For Greedy
119
+
- Used in case of optimization problems (maximize of minimize something)
120
+
- When to use heaps vs when to use sorting: When the problem requires just finding the min or max, we can use sorting, but if after finding something is to be inserted again for which in case of sorting it will take O(n) time as it requires finding the place, heaps are better as they take only O(logn) time to do the same thing.
121
+
- In order to represent nodes using bits etc, (eg: huffman coding), we use trees.
122
+
- Huffman codes or optimal merge patterns where something is to be minimized, always choose the maximum
123
+
value to be at the top of the tree with min edge length (or path to be traversed) and min at bottom with
124
+
max edge or path to be traversed to minimize work.
118
125
119
126
# Topic0: Programming Questions
120
127
@@ -279,6 +286,13 @@ values.
279
286
-[Find the smallest window in the string containing all characters of another string](/strings/question11.c)
280
287
-[Find first non-repeating characters from a stream of characters](/strings/question12.c)
281
288
289
+
### Greedy
290
+
291
+
-[Make a program for greedy knapsack problem](/greedy/question1.c)
292
+
-[Make a program to implement huffman encoding](/greedy/question2.c)
293
+
-[Make a program to sequence given jobs with deadlines to maximize profits](/greedy/question3.c)
294
+
-[Optimal merge patterns](/greedy/question4.c)
295
+
282
296
## Some important concepts to solve algos better
283
297
284
298
- For extreme values refer to limits.h constants given by C
- Two strings are anagrams if they have same no of characters and they are composed of the same letters.
356
370
Even if there are repetitions, they are going to be same.
357
371
- Ideal approach of writing a program is return from a functiona and keep strings at a single place and not scattered
372
+
- Greedy method and DP are two programing paradigms which can be used to solve optimization problems
373
+
- Greedy method fractions are allowed
374
+
- For huffman coding to work letters must not be uniformly distributed
375
+
- Spanning tree is min number of edges present in the graph such that all nodes are connected. Span tree is always subgraph of the main graph and cannot contain edges which are not present in the main graph
376
+
- Number of edges incident on the node is degree of node in undirected graphs. In case of directed, there is no degree but in degree and out degree
377
+
- Kirchoff theorem is used to find spanning tree of non-weighted undirected simple graph
0 commit comments