Due at the beginning of class, Wed September 6th. Each solution should take up at most one page. You should do this problem set entirely on your own.
- Show that
is a convex function. Write its gradient and Hessian.
- Consider a one-dimensional function that is twice-differentiable everywhere. Given access to the function value, gradient and second derivative, is it possible to choose a step size
so that the function value
is strictly less than
? If not, how can you use obtain a point
with either smaller function value or
?
- A contiguous subsequence of a list
is a subsequence made up of consecutive elements of
. For instance, if
is (5, 15, −30, 10, −5, 40, 10) then (15, −30, 10) is a contiguous subsequence, but (5, 15, 40) is not. Give a linear time algorithm for the following task:
Input: A list of numbers,.
Output: The contiguous subsequence of maximum sum (a subsequence of length zero has sum zero).
For the preceding example, the answer would be (10, −5, 40, 10), with a sum of 55. - Suppose a CS curriculum consists of
courses, all of them mandatory. Additionally, some of these courses require one or more prerequisite courses to have been taken in a previous semester. All such classes have a higher course number than their prerequisites (so there can never be a loop of classes that require each other). Assuming that a student can take any number of courses in a given semester, give an algorithm that takes the courses and prerequisites as input and computes the minimum number of semesters necessary to complete the curriculum. The running time of the algorithm should be linear in the number of courses and prerequisites.
- You are given an infinite array
in which the first
cells contain positive integers in sorted order and the rest of the cells are not defined. By not defined, we mean that if an algorithm probes a position
then the program returns an error message. You are not given the value of
. Describe an
comparison algorithm that takes a positive integer
as input and finds a position in the array containing
, if such a position exists, and returns NO otherwise.
- Let
be an array of
distinct unsorted numbers. Say that a pair
is an inversion on
if and only if
. Give an
comparison algorithms that determines the number of inversions of a given array of
distinct unsorted integers.
- A vertex coloring of a graph is an assignment of natural number labels called colors to each vertex. A valid vertex coloring of a graph is a vertex coloring such that no pair of adjacent vertices share the same color. Consider the following algorithm for greedily coloring the vertices of a graph: for each vertex in the graph (taken in a random order), set that vertex’s color to be the lowest natural number that is not shared by any adjacent vertex. Give a brief argument explaining why this algorithm results in a valid coloring. What is the maximum number of colors the algorithm might use?