MPCS 55001 Algorithms — Winter 2020

Homework 1. This problem set is due Monday January 13 at 11:59 pm. It must be submitted electronically to Canvas.

Reading: CLRS chapters 1–3; chapter 4, sections 4.1, 4.3–4.5. Reading for lecture 2: chapters 5, 7, and 11.

Problem assignment:

"Do" Exercises (do but do not submit):

  1. "DO" Exercise 2.3-5, page 39.

  2. "DO" Exercise 2.3-7, page 39. Write pseudocode for your algorithm.

  3. "DO" Problem 2-1, pages 39–40.

  4. "DO" Problem 2-4, pages 41–42.

  5. "DO" Exercise 3.1-1, page 52.

  6. "DO" Exercise 4.5-1, page 96.

  7. "DO" Problem 30-1, parts a and c, pages 920–921.

Homework Assignment: DUE Monday January 13 at 11:59 pm

Homework Problems:

  1. HW We are given an array A[1.. n] of n real numbers, n ≥ 3, with the property that A[1] ≥ A[2] and A[n − 1] ≤ A[n]. We say that an element A[x] is a local minimum if A[x − 1] ≥ A[x] and A[x] ≤ A[x + 1].
    Example: There are 6 local minima in the following array:


    We obviously can find a local minimum in O(n) time by scanning through the array. Give a divide and conquer algorithm that finds a local minimum in O(lg n) time. Your algorithm should return the index of a local minimum. You may use the following test data as an example to help you understand this problem and write correct pseudocode: readme   input   output. Now suppose we generalize the problem to two dimensions. The input is an m × n matrix M of real numbers. An element M[x, y] is a local minimum if no neighbor has a strictly lower value (equivalently, if all neighbors have equal or higher values). Give an efficient algorithm to find a local minimum on this input. Your algorithm should return an ordered pair of indices of a local minimum.

  2. HW (a) Given an array A[1.. n] of n real numbers, give an algorithm to compute the number of "distinct pairs", which are ordered pairs of indices (i, j) such that A[i] ≠ A[j], in O(n lg n) time.
    Example:
                          A = [10,   10,   19]
                          distinct pairs: (1, 3), (2, 3), (3, 1), (3, 2)
                          count: 4
    (b) Given an array A[1.. n] of n real numbers, give an algorithm to compute the number of "distinct triples", which are indices (i, j, k) such that A[i], A[j], A[k] are distinct, in O(n2) time.

  3. HW Consider two square matrices X and Y of size n = 2k, where k is a positive integer. Let Z denote their product, i.e.,

    XY = Z,
    where X, Y, and Z are all of size n, i.e., n × n matrices, with real-number entries. (See here for a refresher on matrices and matrix multiplication. Of particular interest is the section on "Block matrices and submatrices" on page 9.) Observe that Z can be computed using a divide-and-conquer approach. The first step is to divide the two input matrices into quadrants, as follows:

    For example, if
    then
    Note that these quadrants are square matrices of size n/2. Furthermore, they can be used to compute the quadrants of Z as follows:

    A second, more clever algorithm involves defining 7 new square matrices of size n/2 as follows:


Gerry Brady, Chris Jones, Tushant Mittal, and Andrew Eckart
Monday January 6 20:56:03 CST 2020