Greedy?

In general, Greedy is perceived as the one who thinks of instantaneous gains.

In computation,

Its the same but here its related to making decision which seem's more appropriate at any instant. 

Any real life example?

Whom do you call greedy?

Easiest Approach to come up with but have no proof of its correctness most of the times.

 

These are the easiest of all the approaches that are used in the solutions of the algorithmic problems.

Area of Application:

  1. Dijkstra's Algorithm
  2. Kruskal's MST Algorithm
  3. Prim's MST Algorithm
  4. Huffman Coding Compression Algorithm

Using Greedy Approach:

( Try yourself )

Task: Reach form 0 to 4 with minimum overall path sum.

Seen a problem try to sorting the input.

 

May be you come up with a solution. 

Sorting itself is greedy.

Any type of sorting you can take as an example.

How to spot a greedy algorithm?

  • Do I have a choice between different alternatives at some point?
  • Does this choice result in sub-problems that can be solved individually?
  • Will I be able to use the solution of the sub-problem to derive a solution for the overall problem?

Let's apply what we have just learnt.

Sample Input

4 100
30 40 40 50

Sample Output

YIPPIE

Copy of deck

By Pulkit Goyal

Copy of deck

  • 829