All work should be done on your own. If you discuss this assignment in any way with anyone else, or find help for getting the answer from any source, you must state so clearly at the top of your submission. There should be no working together except to understand the question.

  1. Consider the function:

    fxy = fx2y+ fxy2 ; xy>1 1 ; x1y1
    1. Prove that a program which solves this recursively will always halt.

      Consider a similar function:

      gx = gx2+1 ; x>1 1 ; x1

      The expansion of this function will look like:

      gx = gx2+1 = gx22+2 = gx23+3 = gx2i+i

      This expansion will continue until 2ix. Since, by definition:

      xya 1 x ya a logyx

      x ∃ log2x ∋ the recursion will halt after log2x iterations. Since 1 is added each iteration with an extra 1 when x ≤ 2i, g(x) may also be expressed as:

      gx = log2x +1 ; x>1 1 ; x1

      The original function, f(x,y), reduces each of its recursive addends in a manner similar to g(x) and will eventually terminate.


      A more interesting proof was given in class:

      Assume that the pair (x, y) is the smallest pair of values for which the algorithm will not halt. The ordering of the pairs (x, y) is lexigraphical, that is:

      xy < xy+k < x+ky k k1

      The expansion then is:

      fxy = fx2y+ fxy2

      As defined by the ordering:

      x2y < xy2 < xy

      Since (x, y) was the minmum value that f(x, y) would halt on, each of the addends will halt, f(x, y) will then halt, so (x, y) cannot exist.

    2. What is f(x,2)?

      fx2 = fx22+ fx22 = fx22+1 = fx222+ fx222+1 = fx222+2 = fx232+ fx2222+ 2 = fx232+3 = fx2i2+i = gx

      Support for this conclusion is given by a program which compares the recursive solution to log2(x) + 1.

  2. Suppose that you have a recurrence of the form Tn= n2Tn2 +1 . What is the solution in terms of order notation?

    Recall:

    fn = Ogn c Tfn cgn n ogn < Ωgn Θgn =

    Consider the expansion of the expression:

    Tn = n2Tn2+1 = n2 n22 Tn22+1 +1 = n223 Tn22 +n2 +1 = n223 n23 Tn23+1 +n2 +1 = n326 Tn23 +n23 +n2 +1 = n326 n24 Tn24+1 +n23 +n2 +1 = n4210 Tn24 +n26 +n23 +n2 +1 = nm 2 Σ j=1 m+1 j T1 + Σ i=1 m n 2 Σj=1i j +1 m= log2n = nm 2 m+1 m+2 2 T1 + Σ i=1 m n 2 ii+12 +1 = nm 2 - m+1 m+2 T1 + nm Σ i=1 m 2 -ii+1 +1 < nm 2 -m2 T1 + nm Σ i=1 m 2 -i2 = O nlog2n nlog2n2 = O n log2n- log2n2 = O nlog2n2 = O nlogn2

    I originally ended up with Onlogn , and in all honesty don't entirely understand this solution.


    One option for determining the solution is not the "master theorem." Consider a general expression:

    Tn = aTnb+ fn = blogba Tnb+ nlogba fn nlogba = bp Tnb+ npgn p=logba gx= fnnp = npgn+ npgnb+ b2p Tnb2 = npgn+ npgnb+ npgnb2+ b3p Tnb3 = np gn+ gnb+ gnb2+ + gnbi +bip Tnbi = np Σ i=0 logbn gnbi +bplogbn Tnblogbn = np Σ i=0 logbn gnbi +np T1

    There are three options for how g(n) will perform:

    • gn is increasing • the gn term will dominate the expression
    • gn is constant • the gnbi terms will all matter
    • gn is decreasing • the g1 term will dominate the expression

    For this particular problem, T(n) is modified by a factor f(n) rather than a constant, so the solution cannot be applied.

  3. In a certain set decomposition algorithm, a set is split into two non-intersecting subsets and the subsets are recursively subdivided. Each decomposition takes time propotional to the square of the number of elements in the current set being decomposed.

    1. Show that the worst case time for this decomposition is Θ(n3).

      The size of the subsets will be:

      n = n1+n2 = anc+ c-anc

      The time for generating each of these subsets is:

      Tn = cn2+ Tn1+ Tn2

      This combination has a minima when n1 = n2. The maximum is when one element is as large as possible. Because each subset must contain at least one element or the algorithm will not progress, this is:

      n1 = n-1 Tn = cn2+ Tn1+ Tn2 = cn2+ Tn-1 +T1 = cn2+ cn-12 +Tn-2 +T1 +T1 = cn2+ cn-12 +Tn-2 +2T1 = Σ i=0 k c n-i2 +Tn-k +kT1 = c Σ i=0 n-1 n-i2 +nT1 = Θn3
    2. Show that if the decomposition has the property that neither subset of a decomposition step has more than 34 of the elements from the set being decomposed, the worst case of the decomposition is Θ(n2).

      As before, the worst case scenario is when one element, ni, is maximized. The exact nature of that decomposition is a bit tricky, however. The most obvious method for maximizing one quantity is to say:

      n = 3n4+ n4

      However, since nn1n2 there are times that it will not be posible to have a decomposition that divides evenly. The best case for maximization is:

      n1 3n4 , n2 n2

      Hypothesize that:

      Tn kn2 Tn = cn2+ Tn1+ Tn2 < cn2+ T3n4 +Tn2 cn2+ k3n42 +kn22 = cn2+ 13kn216

      I'm missing a step, then it's:

      cn2 13kn216 k 16c13