ALGORITHM DESIGN


Greedy algorithms. A greedy algorithm solves an optimization problem by making locally optimal choices at each step. Greedy algorithms typically do not compute globally optimal solutions. In some cases they do (but typically require a non-trivial argument to show why), and in others they can still produce good (but not optimal) results.
Familiar examples (all of which do compute globally optimal solutions):

Network flow. Many problems can be modeled as problems on edge-weighted graphs and digraphs:

Reducing a problem to one of these fundamental network problems is often an effective strategy. Familiar examples:

Divide-and-conquer. Divide-and-conquer algorithms solve a problem by breaking it into into subproblems, recursively solving each subproblem, and combining the results.
Familiar examples:

Dynamic programming. Dynamic programming is design strategy that is similar to divide-and-conquer. The defining characteristic of dynamic programming is that the subproblems overlap, and we store the solution to each subproblem to avoid the cost of re-computing it.
Familiar examples:

Randomization. A randomized algorithm is an algorithm whose run-time (or output) depends on the results of random coin flips. Randomized algorithms are typically evaluated on the basis of their expected running time the average of all its possible run-times weighted by their probability).
Familiar examples:

Recommended Problems

C level

  1. Let G be a directed graph. A coloring of G is a function mapping each vertex to a color, so that no two adjacent vertices are assigned the same color. Greedy graph coloring coloring is an algorithm that computes a coloring as follows. Call the available colors the palette, and suppose that there is a natural order on the colors (e.g., the smallest color is red, followed by blue, followed by green, and so on). Traverse the vertices of the graph (in any order), at each step assigning the vertex the lowest color in the palette that is not already assigned to one of its neighbors. Does greedy graph coloring produce a globally optimal result (i.e., using the fewest colors from the palette)? Why or why not?
    Answers

B level

  1. Design an algorithm that generates a number uniformly at random between 0 and n that is not divisible by 7 or 11, and analyze its running time.
    Answers
  2. Imagine that we have an n-by-n grid, such that some squares on the grid are filled with obstacles. A robot located at in the bottom left corner of the grid, and wishes to move to the top right corner by a sequence of moves (go up, go right, go diagonally up and to the right) while avoiding squares that contain obstacles. Design an algorithm to determine the number of ways a robot may accomplish this task.
    Answers

A level

  1. Suppose that G is a graph where each edge e is associated with a positive capacity ce and each vertex v is associated with an integer demand dv (note that dv can be positive (indicating a demand), negative (indicating a supply), or zero). A circulation is an function f mapping vertices to integers such that Design an algorithm to determine whether a graph has a circulation.
    Answers