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 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 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,
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 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 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
CS 473 ] Spring 2017
Y Homework 1 Z
Due Wednesday, February 1, 2017 at 8pm
Starting with this homework, groups of up to three people can submit joint solutions. Each
problem should be submitted by exactly one person, and the beginning of the homework shou
CS 473 ] Spring 2017
Y Homework 2 Z
Due Wednesday, February 8, 2017 at 8pm
There are only two problems, but the first one counts double.
1. Suppose you are given a two-dimensional array M [1 . n, 1 . n] of numbers, which could
be positive, negative, or ze
CS 473 ] Spring 2017
Y Homework 5 Z
Due Wednesday, March 8, 2017 at 8pm
1. Reservoir sampling is a method for choosing an item uniformly at random from an
arbitrarily long stream of data.
GetOneSample(stream S):
`0
while S is not done
x next item in S
`+1
CS 473 ] Spring 2017
Y Homework 5 Z
Due Wednesday, February 15, 2017 at 8pm
0. [Warmup only; do not submit solutions]
After sending his loyal friends Rosencrantz and Guildenstern off to Norway, Hamlet
decides to amuse himself by repeatedly flipping a fair
CS 473 ] Spring 2017
Y Homework 6 Z
Due Wednesday, March 16, 2017 at 8pm
1. Suppose you are given a directed graph G = (V, E), two vertices s and t, a capacity function
c : E R+ , and a second function f : E R. Describe and analyze an algorithm to
determi
CS 473 ] Spring 2017
Y Homework 7 Z
Due Wednesday, March 29, 2017 at 8pm
1. Suppose we are given an array A[1 . m][1 . n] of non-negative real numbers. We want
to round A to an integer matrix, by replacing each entry x in A with either bxc or dxe,
without
CS 473 ] Spring 2017
Y Homework 4 Z
Due Wednesday, March 1, 2017 at 8pm
1. Recall that a priority search tree is a binary tree in which every node has both a search key
and a priority, arranged so that the tree is simultaneously a binary search tree for t
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
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 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