



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An overview of the greedy approach, an algorithmic paradigm that follows local optimal choices at each step with the hope of finding a global optimal solution. It discusses the properties of greedy algorithms, such as the greedy choice property and optimal substructure, and presents the fractional knapsack problem as an example where a greedy algorithm can be applied. The problem statement, the algorithm, and the analysis of the time complexity. It covers key concepts like feasibility, local optimal choice, and unalterability in the context of greedy algorithms. This information could be useful for students studying algorithms, optimization problems, and problem-solving techniques in computer science or related fields.
Typology: Schemes and Mind Maps
1 / 5
This page cannot be seen from the preview
Don't miss anything!
In greedy approach, the decision is taken on the basis of current available information without worrying about the effect of the current decision in future. Greedy algorithms build a solution part by part, choosing the next part in such a way, that it gives an immediate benefit. This approach never reconsiders the choices taken previously. This approach is mainly used to solve optimization problems. Greedy method is easy to implement and quite efficient in most of the cases. Hence, we can say that Greedy algorithm is an algorithmic paradigm based on heuristic that follows local optimal choice at each step with the hope of finding global optimal solution. In many problems, it does not produce an optimal solution though it gives an approximate (near optimal) solution in a reasonable time. Greedy Method finds out of many options, but you have to choose the best option." In this method, we have to find out the best method/option out of many present ways. In this approach/method we focus on the first stage and decide the output, don't think about the future. This method may or may not give the best output. Greedy Algorithm solves problems by making the best choice that seems best at the particular moment. Many optimization problems can be determined using a greedy algorithm. Some issues have no efficient solution, but a greedy algorithm may provide a solution that is close to optimal. A greedy algorithm works if a problem exhibits the following two properties:
A thief is robbing a store and can carry a maximal weight of W into his knapsack. There are n items available in the store and weight of ith^ item is wi and its profit is pi. What items should the thief take? In this context, the items should be selected in such a way that the thief will carry those items for which he will gain maximum profit. Hence, the objective of the thief is to maximize the profit. Based on the nature of the items, Knapsack problems are categorized as Fractional Knapsack Knapsack
As the provided items are not sorted based on pi/wi. After sorting, the items are as shown in the following table. Item B A C D Profit 100 280 120 120 Weight 10 40 20 24 Ratio (pi/wi) 10 7 6 5 Solution After sorting all the items according to pi/wi. First all of B is chosen as weight of B is less than the capacity of the knapsack. Next, item A is chosen, as the available capacity of the knapsack is greater than the weight of A. Now, C is chosen as the next item. However, the whole item cannot be chosen as the remaining capacity of the knapsack is less than the weight of C. Hence, fraction of C (i.e. (60 − 50)/20) is chosen. Now, the capacity of the Knapsack is equal to the selected items. Hence, no more item can be selected. The total weight of the selected items is 10 + 40 + 20 * (10/20) = 60 And the total profit is 100 + 280 + 120 * (10/20) = 380 + 60 = 440 This is the optimal solution. We cannot gain more profit selecting any different combination of items.
Analysis If the provided items are already sorted into a decreasing order of pi/wi, then the while loop takes a time in O(n) ; Therefore, the total time including the sort is in O(n logn).