Chapter 6
Dynamic programming
In the preceding chapters we have seen some elegant design principlessuch as divide-andconquer, graph exploration, and greedy choicethat yield denitive algorithms for a variety of important computational tasks. The drawback o
Chapter 1
Algorithms with numbers
One of the main themes of this chapter is the dramatic contrast between two ancient problems that at rst seem very similar: Factoring: Given a number N , express it as a product of its prime factors. Primality: Given a nu
Chapter 4
Paths in graphs
4.1 Distances
Depth-rst search readily identies all the vertices of a graph that can be reached from a designated starting point. It also nds explicit paths to these vertices, summarized in its search tree (Figure 4.1). However,
Chapter 16 Network Flow V - Min-cost flow
By Sariel Har-Peled, October 19, 2007x Version: 1.01
16.1
Minimum Average Cost Cycle
Let G = (V, E) be a digraph (i.e., a directed graph) with n vertices and m edges, and : E IR be a weight function on t
Chapter 0
Prologue
Look around you. Computers and networks are everywhere, enabling an intricate web of complex human activities: education, commerce, entertainment, research, manufacturing, health management, human communication, even war. Of the two mai
Chapter 2
Divide-and-conquer algorithms
The divide-and-conquer strategy solves a problem by: 1. Breaking it into subproblems that are themselves smaller instances of the same type of problem 2. Recursively solving these subproblems 3. Appropriately combin
Chapter 5
Greedy algorithms
A game like chess can be won only by thinking ahead: a player who is focused entirely on immediate advantage is easy to defeat. But in many other games, such as Scrabble, it is possible to do quite well by simply making whichev
Preface
This book evolved over the past ten years from a set of lecture notes developed while teaching the undergraduate Algorithms course at Berkeley and U.C. San Diego. Our way of teaching this course evolved tremendously over these years in a number of
Chapter 10
Quantum algorithms
This book started with the worlds oldest and most widely used algorithms (the ones for adding and multiplying numbers) and an ancient hard problem (FACTORING). In this last chapter the tables are turned: we present one of the
Chapter 8
NP-complete problems
8.1 Search problems
Over the past seven chapters we have developed algorithms for nding shortest paths and minimum spanning trees in graphs, matchings in bipartite graphs, maximum increasing subsequences, maximum ows in netw
Chapter 9
Coping with NP-completeness
You are the junior member of a seasoned project team. Your current task is to write code for solving a simple-looking problem involving graphs and numbers. What are you supposed to do? If you are very lucky, your prob
Chapter 1
Algorithms with numbers
One of the main themes of this chapter is the dramatic contrast between two ancient problems that at rst seem very similar: Factoring: Given a number N , express it as a product of its prime factors. Primality: Given a nu
Chapter 1 NP Completeness I
By Sariel Har-Peled, September 17, 2007x Version: 1.04
"Then you must begin a reading program immediately so that you man understand the crises of our age," Ignatius said solemnly. "Begin with the late Romans, including B
Chapter 2 NP Completeness II
By Sariel Har-Peled, September 17, 2007x Version: 1.02
2.1
Max-Clique
We remind the reader, that a clique is a complete graph, where every pair of vertices are connected by an edge. The MaxClique problem asks what is t
Chapter 3 NP Completeness III
By Sariel Har-Peled, September 17, 2007x Version: 1.0
3.1
Hamiltonian Cycle
Definition 3.1.1 A Hamiltonian cycle is a cycle in the graph that visits very vertex exactly once. Definition 3.1.2 An Eulerian cycle is a cy
Chapter 15 Network Flow IV - Applications II
By Sariel Har-Peled, October 19, 2007x Version: 0.11
15.1
Airline Scheduling
Problem 15.1.1 Given information about flights that an airline needs to provide, generate a profitable schedule. The input is
Chapter 8 Network Flow III - Applications
By Sariel Har-Peled, October 15, 2007x Version: 0.1
8.1
8.1.1
Edge disjoint paths
Edge-disjoint paths in a directed graphs
Question 8.1.1 Given a graph G (either directed or undirected), two vertices s and
Chapter 7 Network Flow II - The Vengeance
By Sariel Har-Peled, October 15, 2007x Version: 0.1
7.1
Accountability
The comic in Figure 7.1 is by Jonathan Shewchuk and is referring to the Calvin and Hobbes comics. People that do not know maximum flow
Chapter 12 Network Flow
By Sariel Har-Peled, October 9, 2007x Version: 0.25
12.1
Network Flow
We would like to transfer as much "merchandise" as possible from one point to another. For example, we have a wireless network, and one would like to tra
Chapter 11 Min Cut
By Sariel Har-Peled, October 1, 2007x
To acknowledge the corn - This purely American expression means to admit the losing of an argument, especially in regard to a detail; to retract; to admit defeat. It is over a hundred years ol
Chapter 10 Randomized Algorithms II
By Sariel Har-Peled, September 28, 2007x Version: 0.1
10.1
QuickSort with High Probability
One can think about QuickSort as playing a game in rounds. Every round, QuickSort picks a pivot, splits the problem into
Chapter 9 Randomized Algorithms
By Sariel Har-Peled, September 20, 2007x Version: 0.26
9.1
Some Probability
Definition 9.1.1 (Informal.) A random variable is a measurable function from a probability space to (usually) real numbers. It associates a
Chapter 8 Approximation algorithms III
By Sariel Har-Peled, September 19, 2007x Version: 0.2
8.1
Clustering
Consider the problem of unsupervised learning. We are given a set of examples, and we would like to partition them into classes of similar
Chapter 7 Approximation algorithms II
By Sariel Har-Peled, September 17, 2007x Version: 0.2
7.1
Max Exact 3SAT
We remind the reader that an instance of 3SAT is a boolean formula, for example F = (x1 + x2 + x3 )(x4 + x1 + x2 ), and the decision pro
Chapter 6 Approximation algorithms via Greediness
By Sariel Har-Peled, September 17, 2007x Version: 0.2
6.1
Greedy algorithms and approximation algorithms
A natural tendency in solving algorithmic problems is to locally do whats seems to be the ri
Chapter 5 Dynamic programming II - The Recursion Strikes Back
By Sariel Har-Peled, September 17, 2007x Version: 0.4
"No, mademoiselle, I don't capture elephants. I content myself with living among them. I like them. I like looking at them, listening
Chapter 4 Dynamic programming
By Sariel Har-Peled, September 6, 2007x
The events of 8 September prompted Foch to draft the later legendary signal: "My centre is giving way, my right is in retreat, situation excellent. I attack." It was probably neve