50 Greedy Algorithm Programs in C for Freshers

Basic Greedy Programs

# Program Name Description Resources
1 Activity Selection Select max non-conflicting activities GeeksforGeeks
2 Job Sequencing with Deadlines Maximize profit within deadlines GeeksforGeeks
3 Fractional Knapsack Maximize value with fractional items GeeksforGeeks
4 Minimum Number of Coins Find minimum coins for change (Indian/standard currency) GeeksforGeeks
5 Huffman Coding Lossless data compression encoding GeeksforGeeks
6 Minimum Spanning Tree (Prim's) Prim's algorithm for MST GeeksforGeeks
7 Minimum Spanning Tree (Kruskal's) Kruskal's algorithm using union-find GeeksforGeeks
8 Dijkstra's Algorithm Shortest path from single source GeeksforGeeks
9 Minimum Platforms Minimum platforms for railway station GeeksforGeeks
10 Water Connection Problem Minimum pipes to connect houses GeeksforGeeks
11 Egyptian Fraction Represent fraction as sum of unit fractions GeeksforGeeks
12 Maximize sum of array after k negations Maximize sum by negating elements k times GeeksforGeeks
13 Greedy coloring of graph Color graph vertices with minimum colors GeeksforGeeks
14 Minimum sum of two numbers formed by digits Arrange digits to form two smallest numbers GeeksforGeeks
15 Smallest subset with sum greater than all other elements Find smallest subset with max dominance GeeksforGeeks
16 Connect n ropes with minimum cost Merge ropes optimally (min-heap) GeeksforGeeks
17 Minimum jumps to reach end Greedy solution for array jump game GeeksforGeeks
18 Police and thieves Catch maximum thieves using greedy GeeksforGeeks
19 Rearrange characters for no two adjacent same Greedy rearrangement of string GeeksforGeeks
20 Largest number with given sum Construct largest number with digit sum S GeeksforGeeks
21 Smallest number with given sum and digits Smallest number with digit sum S and m digits GeeksforGeeks
22 Maximum trains for which stoppage can be provided Platform train stopping optimization GeeksforGeeks
23 Minimum cost to cut board into squares Greedy cutting board optimization GeeksforGeeks
24 Choose and swap Swap digits to make largest number GeeksforGeeks
25 Maximum sum of absolute difference Arrange numbers to maximize absolute diff sum GeeksforGeeks
26 Split array into consecutive subsequences Greedy splitting for consecutive sequences GeeksforGeeks
27 Minimum deletions to make string balanced Greedy removal for balanced string GeeksforGeeks
28 Car fueling problem Minimum refueling stops GeeksforGeeks
29 Gas station problem Find starting point for circular tour GeeksforGeeks
30 Assign mice to holes Minimize time for mice to reach holes GeeksforGeeks
31 Minimum cash flow among friends Settle debts with minimum transactions GeeksforGeeks
32 Minimum time to complete all tasks Schedule tasks with cooldown GeeksforGeeks
33 Minimum number of arrows to burst balloons Greedy balloon burst interval GeeksforGeeks
34 Non-overlapping intervals Remove min intervals to make non-overlapping GeeksforGeeks
35 Maximum length of pair chain Longest chain of pairs (like activity selection) GeeksforGeeks
36 Remove k digits to form smallest number Build smallest number after removing k digits GeeksforGeeks
37 Largest subarray with 0 sum (greedy approach) But typically hashmap; Greedy variation GeeksforGeeks
38 Minimum rotations to unlock circular lock Greedy min rotations GeeksforGeeks
39 Maximize stock profit with multiple transactions Greedy valley-peak approach GeeksforGeeks
40 Minimum cost to hire k workers Greedy based on wage/quality ratio GeeksforGeeks
41 Two water jug problem (greedy refill) Greedy steps to measure target volume GeeksforGeeks
42 Maximize distinct elements after at most k changes Greedy removal of duplicates GeeksforGeeks
43 Smallest subset with sum greater than each element Greedy pick largest GeeksforGeeks
44 Chocolate distribution problem (greedy diff) Minimize diff between max and min chocolates GeeksforGeeks
45 Minimum increment/decrement to make array non-increasing Greedy adjustments GeeksforGeeks
46 Partition array into two subsets with minimum sum diff Greedy approximate (better with DP) GeeksforGeeks
47 Fit shelves problem Minimize leftover space using larger shelves GeeksforGeeks
48 Largest palindrome possible by rearranging k digits Greedy palindrome construction GeeksforGeeks
49 Maximize number of 1s by flipping at most k 0s Sliding window / greedy GeeksforGeeks
50 Greedy algorithm for Egyptian fraction Already covered; revisit with scaling GeeksforGeeks

30 Essential Greedy Techniques in C

# Technique Name Description Resources
1Activity/Interval SchedulingPick non-overlapping intervals by finish timeGfG
2Sorting by finish/end timeCore to interval problemsGfG
3Min-heap / Max-heap for selectionUsed in Huffman, merging ropesGfG
4Fractional selectionPick by value/weight ratioGfG
5Deadline sequencing with slotsSchedule jobs with unit timeGfG
6Disjoint set union (Kruskal)Union-find for MSTGfG
7Prim's MST using adjacencyPick minimum edge crossing cutGfG
8Dijkstra's shortest pathGreedy BFS with priority queueGfG
9Earliest deadline firstReal-time schedulingGfG
10Greedy coloringAssign color with smallest availableGfG
11Maximize distinct by frequencyUse priority queue for rearrangementGfG
12Minimum product subsetPick negative numbers wiselyGfG
13Maximize sum after k negationsRepeatedly flip smallestGfG
14Greedy on digits (largest/smallest)Fill digits from leftGfG
15Two-pointer greedyFor pairs like mice & holesGfG
16Gas station (circular tour)Greedy deficit trackingGfG
17Interval partitioning (min classrooms)Minimum resources for intervalsGfG
18Minimize cash flowSettle using net balanceGfG
19Chocolate distribution (min diff)Sort and sliding windowGfG
20Remove k digits (monotonic stack/greedy)Use stack for smallest numberGfG
21Greedy on trees (center reduction)Minimum vertex cover for treeGfG
22Max product of three numbersPick largest three or two negative+largestGfG
23Minimum sum of absolute differencesPair smallest with smallestGfG
24Greedy for palindrome formationAssign digits symmetricallyGfG
25Minimum refueling stopsMax heap for fuelsGfG
26Smallest subset with sum > halfPick largest elements greedilyGfG
27Greedy for Egyptian fractionRepeatedly pick floor(d/n) denominatorGfG
28Split into consecutive subsequencesGreedy with frequency mapsGfG
29Minimum cost to connect nodes (cables)Similar to merging ropesGfG
30Greedy on ranges (cover points)Minimum points to cover intervalsGfG

Related Greedy Resources