Solutions to Problem Set #1, CS 255, February 20, 2006

  1. The analogous proof fails. Using the constant 3, the number of elements that can be guaranteed to be eliminated is at least 2[(n/3)(1/2) - 2] = n/3 - 4. So the analogous recurrence becomes
    T(n) <= an + c(1 + n/3) + c(2n/3 + 4)
    For this to be bounded above by cn, we need
      an + c(1 + n/3) + c(2n/3 + 4) <= cn, or
      an + c + cn/3 + 2cn/3 + 4c <= cn, or
      an + c + 4c <= 0.
    Since all of the terms on the left-hand side of the inequality are positive, there is no value of c that will make the inequality true.

    Note that showing that the recurrence does not have a linear solution isn't quite the same thing as showing that the algorithm doesn't have linear time complexity. For one thing, the recurrence is an overestimate, or pessimistic estimate, of the time required by the algorithm.

  2. The time required for the last two steps of the algorithm is Θ(2k + kn), which is Θ(n) assuming that k is independent of n. This is true since setting up the original tournament takes time Θ(2k), and it has to be replayed Θ(n) times doing k comparisons at each replay.

    By analogy with mergesort, the recursion tree method of Section 4.2 of the text can be used to observe there are logarithmically many levels of the recursion tree, each with linear cost. This gives an overall worst-case time complexity of Θ(n log n).

    More formally, the relevant recurrence is

    T(n) <= an + 2kT(n/2k)
    In the master theorem, a = b, so case 2 applies to give that T(n) is Θ(n log n). This asymptotic result could also be obtained by the substitution method. Θ(n log n) is a reasonable guess for the asymptotic result, since it's the best-possible worst-case time complexity for comparison-based sorting, as described in Section 8.1.

    Although the algorithm of this exercise may not have any obvious advantages over the other
    Θ(n log n) sorting algorithms, it does exhibit very good locality of reference. That is, data that is needed at any point of the algorithm is likely to be stored very close to data that has been recently used. This makes the algorithm a useful one for sorting sequences that are too large to fit into main memory.

  3. The matrices corresponding to the arrays m and s of the text are given below.
          0 3000 1750 4750 4500                -  1  1  3  3
               0 1000 3000 3500                   -  2  3  3
                    0 4000 3000                      -  3  3
                         0 2000                         -  4
                              0                            -
    If the original matrices are called A1 through A5, then the optimal order of the computation is given by
    ((A1 x (A2 x A3)) x (A4 x A5))
    and requires 4500 element multiplications.