CISC 320 Algorithms and Advanced Programming, Fall, 2002.
Homework set #3.                     Due Tue, Nov 26.

  1. Textbook problem R-5.9

  2. Consider this version of fast exponentiation mod n:
    int mulmod(int a, int b, int n){return (a*b)%n;}
    int expmod(int a, int e, int n) // assume e and n positive
    {
        if ( 1 == e )  // base case
            return a;
        if ( 0 == e%2 ) // e is even
            return expmod( mulmod(a, a, n), e/2, n ); // a^(2k) = (a^2)^k mod n
        else // e is odd
            return mulmod( a, expmod( mulmod(a, a, n), e/2, n ), n ); // a^(2k+1) = a(a^2)^k mod n
    }
    
    In the computation of expmod(2, e, 89) a certain number of calls to mulmod will be made, depending on e. For e from 1 to 1000, what is the most number of calls to mulmod for any given e? List all of the e's up to 1000 for which this maximum number of mulmod calls occurs. Briefly explain why your list is correct.

  3. Consider the number of remainders that are computed in the extended Euclidean algorithm. Show that, the worst case number of remainders is not more than about 2lg(n), where n is the larger of the two input numbers, a and b.

    Hint: Let rk denote the k-th remainder, where a is r0 and b is r1. Show that rk+2 is not more than half of rk.

    You may work with the recursive description of the algorithm in the text, or this iterative version:`

    int extendedEuclideanAlg(int a, int b, int& i, int& j)
    /* a and b are the inputs.  return value d and the parameters i and j
    are set so that d is the greatest common divisor of a and b and 
    d = i*a + j*b.
    */
    {   int q;  
        int r = a, s = 1, t = 0, 
        int rr = b, ss = 0, tt = 1; 
        int rrr, sss, ttt;
        while (rr != 0) 
        {   q = r/rr; // floor of exact quotient.
            rrr = r - q*rr;
            sss = s - q*ss;
            ttt = t - q*tt;
            // update for next step
            r = rr; rr = rrr;
            s = ss; ss = sss;
            t = tt; tt = ttt;
        } 
        // output
        i = s; j = t; return r;
    }        
    

  4. Compute the inverse of 33, 44, and 55 mod 89. Show your work using the extended Euclidean Algorithm in a table similar to table 10.10 or similar to the one done in class. Notice the variation in the number of remainders involved.

  5. Textbook problem R-10.20

  6. Textbook problem R-10.21

    Hint: in Maple ab mod c and a-1 mod c can be computed by expressions:

    a &^ b mod c;
    a &^ (-1) mod c;
    

  7. We want to multiply polynomials which have integer coefficients. The polynomials have degree less than n, and the coefficients are less than 2n in absolute value. Using the FFT (Fast Fourier Transform) algorithm, polynomials of degree less than n can be multiplied in O(n*lg(n)) arithmetic operations. but here those arithmetic operations may be on rather large integers. Using the Shoenhage-Strassen algorithm, n bit integers can be multiplied in O(n*lg(n)*lg(lg(n))) time. As a function of n, how much time will our integer polynomial multiplication take if we combine these two methods? Give an upper bound for the worst case time which is as small an upper bound as you can find. Explain your reasoning.

    Hint: Let X = n*lg(n) and Y=n*lg(n)*lg(lg(n)). For starters which of these is the most accurate estimate: X + Y, X*Y, XY?

    Also notice that no coefficient in the product polynomial is larger than n*(2n)2. Why is this fact useful/important?