# Hello World! What are Greedy Algorithms?

So hello world.. This would be the first post on this blog.

The posts here would be of the kind that are easy to read, objective oriented, and food for thought.

So this one goes for the beginners… don’t worry, after reading this you will not be a one!

Greedy Algorithms

Definition: An algorithm which makes locally optimum choices with a hope to make the whole outcome optimum.

Points to remember:

• Greedy Algorithms are most commonly proved using two different approaches
• First proving approach is “Stays Ahead” where you prove that your algorithm stays ahead in terms of the underlying criteria w.r.t. to any other approach.
• Second proving approach is called “Exchange Argument”, where you start with the optimal solution and exchange it with the greedy approach using some number of steps so that at each step you prove that you are not decreasing the outcome.

Some Basic Pseudocodes:

Interval Scheduling Problem:

 Problem: Given set of intervals with starting time and end time, give the set of intervals with maximum cardinality such that no intervals overlap. Algorithm: * Initially let R be the set of all requests. * While R is not empty: * Choose a request i with earliest finish time * add to queue A * delete all incompatible from R. * EndWhile * Return A Analysis: * A is compatible * A is optimal with the "Stays Ahead" argument. * Running Time : O(n logn)

Interval Partitioning Problem:

 Problem: Given intervals with finish and end times, partition the intervals into labels with minimum amount of labels so that no two intervals in any label overlap. Algorithm: * Sort Intervals w.r.t. starting time, breaking tries arbitrarily. * Let them be I1, I2, … , In * For j = 1:n * For each (i

Minimize maximum Lateness:

 Problem: Variation of Interval Scheduling, with deadlines and duration given, all must be performed on a single resource, find the ordering with minimum maximum lateness of any interval. Algorithm: * Sort Jobs w.r.t the deadlines * Let them be d1, d2, … ,dn * Initially f=s * For (i=1:n) * Assign s(i) f, f(i) = s(i) + t(i) * f=f(i) * EndFor * Return Analysis: * There is an optimal solution with no idle time. * Proof of optimality by "Exchange Argument"