1. Gyanastra
  2. Algorithms
  3. Greedy Method and Fractional Knapsack
  4. Optimization Problems and Exhaustive Search
Free lesson, no account needed 4 min read 15 practice questions after it
Asked in past papers12 times
  • GATE CSE202620252024202120202019201820172008200520042000

Algorithms · Greedy Method and Fractional Knapsack

Optimization Problems and Exhaustive Search

Overview

An optimization problem asks for the maximum or minimum of some property, such as cost, profit, reliability, risk, shortest path, or minimal spanning tree.
Exhaustive search solves such problems by enumerating every possible solution, but it takes exponential time, so better paradigms — the greedy method and dynamic programming — are needed.

Key concepts

  • Optimization problem: a problem in which some property is to be maximized or minimized. Examples of such properties: minimize cost, maximize profit, maximize reliability, minimize risk, shortest path in a graph (minimize distance/cost), minimal spanning tree (minimize total edge weight).
  • Exhaustive search: find all possible solutions, then pick the one with the least (or greatest) value. It may take exponential time, of order 2n2^n.
  • Greedy method: a programming paradigm that solves only a subset of optimization problems — the problem must have certain properties for greedy to apply.
    When it applies, the solution is generally polynomial: order of nkn^k or nlog⁡nn \log n.
  • Dynamic programming: a programming paradigm that can solve any optimization problem, but its time may be polynomial (order of nkn^k) or exponential (order of 2n2^n).

How it works

  1. Take a graph with nodes A, B, C, D, E and a weight on every edge.
  2. Ask, for example: what is the shortest path from A to C?
  3. Exhaustive search solves it by finding all possible paths from A to C, then choosing the path with the least value.
  4. With nn edges, each edge may or may not be present in a path — two chances per edge — so on the order of 2n2^n paths may have to be examined, and the minimum found among them. This is an order 2n2^n algorithm.
  5. Enumerating all solutions and then finding the minimum takes a lot of time when the problem size is large, so other methods are wanted: the greedy method and dynamic programming.
  6. Greedy applies only when the problem has the required properties; dynamic programming applies to all problems, but is worth applying only when it reduces the time to polynomial.

Formulas

  • Exhaustive search over paths: with nn edges, each edge either present or absent, so the number of paths examined is of order 2n2^n; time complexity O(2n)O(2^n).
  • Greedy method (when applicable): time complexity generally polynomial, order of nkn^k or nlog⁡nn \log n.
  • Dynamic programming: time complexity either polynomial, order of nkn^k, or exponential, order of 2n2^n.

Comparison

AspectGreedy MethodDynamic ProgrammingExhaustive Search
ApplicabilityOnly some optimization problems (problem must have certain properties)Optimization problems with optimal substructure (and overlapping subproblems)Any problem (enumerates all solutions)
Typical time complexityPolynomial: order of nkn^k or nlog⁡nn \log nOrder of nkn^k (polynomial) or order of 2n2^n (exponential)Order of 2n2^n (exponential)
When it is usefulWhen the problem satisfies the required propertiesWhen it reduces the time to polynomial, order of nkn^kBaseline; used when nothing better is available
When it is not usefulFor problems lacking the required properties (may not give the optimal solution)When it still gives order of 2n2^n — as good as exhaustive searchAlways expensive for large problem sizes

Revision summary

  • An optimization problem is one where a property is maximized or minimized.
  • Exhaustive search: enumerate all solutions, then take the minimum/maximum; with nn edges each edge is present or absent, giving order of 2n2^n paths and O(2n)O(2^n) time.
  • The greedy method cannot solve all optimization problems — only a subset having the required properties; given a problem, greedy may not give the optimal solution.
  • When greedy applies, the solution is generally polynomial (nkn^k or nlog⁡nn \log n).
  • Dynamic programming can solve optimization problems that have optimal substructure and overlapping subproblems, but its time may be polynomial (nkn^k) or exponential (2n2^n).
  • Apply dynamic programming only when it gives polynomial time; if it still gives 2n2^n, it is as good as exhaustive search.
  • The methods are best understood through examples rather than through theory about the properties a problem must contain.
Pages 1–2 of 2