CSSE 220 -- Object-oriented Software Development

Homework 18 Due at 8:05 AM on Day 19.

  1. Complete the assigned reading for the next session (see the course schedule). If there is something you do not understand, make a note of it so you can ask about it in class.
  2. Finish the reviews of the other Paint projects that you were assigned.  Fill out the ANGEL surveys.
  3. Finish  the Hardy's Taxi program. Instead of using the turnin script, I will just have you turn your program using Team > Share (SVN). I am giving you a JUnit test suite here. You should practice with the test as soon as your program is producing output, whether it works perfectly or not.  Then if you have problems with that, you will have a chance to get help.

    I reserve the right to change the specific input numbers used by the Hardy test suite before I run your program for actual grading.  I may use a number for N that is bigger than 500, for example.  You should write your program so that it does not set a limit on how big an N it works for.  The only limit should be if your program runs out of memory (which may, in fact, we around that limit). BTW, the tests that use smaller values of n are worth more points.
  4. Do the following written problem.  Bring hard copy (hand-written or typed)  to the next class meeting.
     

    (15 points)  In class we saw that access to any element of a 2-dimensional array is constant-time.  If each item of an M rows and N column array contains b bytes, and L is the memory address of A[0][0], then the address of A[i][j] is L + b*(i*N + j), so two multiplications and two additions are needed regardless of the dimensions of the array.

    A lower-triangular matrix is a (we’ll restrict it to) square matrix (i.e., N x N for some N) in which every element above the main diagonal is zero. I drew a diagram of this on the board in the Day 17 class.  By “above the main diagonal”, we mean an element whose column number is larger than its  row number.  The internal representation of a triangular matrix should be a one-dimensional array.  Since almost half of the positions in the matrix are guaranteed to always be zero, it is not necessary to explicitly store them in the representation array, so we can save almost half of the space needed for a “normal” square matrix with the same number of rows and columns.  Note that the sum, difference, or product of two lower triangular square matrices is lower triangular, so these operations can (and should!) do considerably less work than the corresponding operations for “normal” matrices.

    (a)  (5 points) Show the order in which the elements of an N x N lower-triangular matrix can be stored in the computer's (one-dimensional) memory.

    (b) (10 points)  Given your storage scheme, give the formula for calculating the address in memory of A[i][j] where j ≤ i.  Use A,  L, and b to represent the same things as in the formula from the first paragraph of this problem.   Your formula should be computable in constant time.