Flow Chart for Greedy Algos
seen from United States
seen from United States
seen from China
seen from Iraq

seen from United States
seen from United States

seen from Malaysia
seen from Spain
seen from United States

seen from Malaysia
seen from United States

seen from United States
seen from United States
seen from Dominican Republic
seen from United States
seen from China
seen from Pakistan

seen from Canada

seen from Malaysia
seen from Honduras
Flow Chart for Greedy Algos
Greedy Solution for Jump game - 2
Greedy choice: Similiar to Jump Game 1, I am trying to reach the furthest point possible from a give range, with the (correct) hope that it'll help me reach the end with minimum number of steps.
Greedy Choice for problems solved
Assign Cookies based on size and greed factor - Greedy choice: Give each child the minimum size cookie so larger size cookies are present for future children - Optimal Substructure: the same locally optimal choice made for n children, then n-1 children and so on.
Fractional Knapsack Problem - Greedy Choice: Pick the maximum value/wt at each step to maximise the elements that can be held in the knapsack - Optimal Substructure: same applied for 1,2...n item to be polaced in bag.
Greedy algorithm to find minimum number of coins - Greedy Choice: Since we want to minimize the number of coins, we can start with the maximum currency value that can be provided
Lemonade Change Greedy Choice Property: - Using larger denominations (e.g., $10) for $20 change is better than using smaller ones because it preserves $5 bills for future $10 transactions - For example, if you use three $5s for a $20 bill, you might not have enough $5s to serve a later customer who pays with a $10. Optimal Substructure: - The problem can be decomposed into steps where each decision (giving back $5 or $10) affects the availability of bills for future customers. - The greedy choice of using larger bills first ensures that the solution is globally optimal.
Valid Paranthesis checker:
This approach satisfies the greedy choice property because each decision (treat '' as ')' or '(') is made based on the current state, and the algorithm proceeds step by step, trying to make the best possible choice at each step. The optimal substructure here is that the decision to use a '' as a ')' or '(' at each step affects the remaining possibilities, and the greedy choice leads to the correct overall solution.
So the problem satisfies the greedy property because the algorithm makes choices that are locally optimal (using '' as a closing bracket first) and these choices lead to a globally optimal solution (valid string). The key is that the greedy choice of using '' as a closing bracket first ensures that we have the best chance of meeting the required number of closing brackets, and if that's not possible, using it as an opening bracket allows for more flexibility.
6. N meeting room: - Greedy Choice: We pick the meeting with the minimum ending time, as it leaves the maximum possible time for future meetings to be held.
7. Jump Game:
1. In the greedy approach, maybe the algorithm is not about choosing the maximum possible step each time, but rather keeping track of the maximum reachable index 2. The greedy choice is to always track the farthest you can reach. The key is that at each step, you don't need to look ahead to choose the best path, but rather just keep track of the maximum reach. Because if you can reach a certain index, you can take the maximum possible step from there, which would be the optimal choice. 3. Greedy Choice: At each index i, the best choice is to jump to the farthest reachable index from i. This ensures that we maximize the range of reachable positions, increasing the chance of reaching the end. 4. Optimal Substructure: The problem can be broken down into subproblems where the optimal solution is determined by the farthest reachable index at each step. If the current index is beyond the farthest reachable index, it's impossible to proceed further. 5. No Need for Backtracking: The greedy approach doesn't require checking all possible paths, as it only tracks the farthest reachable index
8. Jump Game - 2
1. Greedy choice: Similiar to Jump Game 1, I am trying to reach the furthest point possible from a give range, with the (correct) hope that it'll help me reach the end with minimum number of steps. 2. See Separate approach post for this under approach.,
Greedy Algorithm
A greedy algorithm is a problem-solving approach that makes the locally optimal choice at each step, with the hope that these choices will lead to a globally optimal solution. Unlike brute-force or dynamic programming methods, greedy algorithms do not explore all possible options but instead make decisions based on the best immediate choice. This approach is efficient but may not always yield the optimal result, depending on the problem's structure.