Chapter 7 Problems

Answer all of the below questions in a simple text file called chapter7.txt, and submit electronically via the usual means.

Suppose that the array A is declared in a language that allows user-defined lower and upper bounds as A[1..3][-2..0][3..5].

  1. Write out all of the elements of A in row-major ordering. Here's a start:

    A[1][-2][3]
    A[1][-2][4]
    A[1][-2][5]
    A[1][-1][3]
    ...
    

  2. How far down the list from the top is A[1][-2][4]? (Really big hint: the answer is 1.)

  3. How far down the list from the top is A[3][-1][4]?

  4. How far down the list from the top is A[3][-2][3]?

  5. How far down the list from the top is A[i][-2][3] for some arbitary i?

  6. Suppose instead that A had been defined as A[L1..U1][-2..0][3..5]. How far down the list from the top is A[i][-2][3]?

  7. Continuing with the above assumptions, how far down the list from the top is A[i][j][3] for some arbitrary j?

  8. Suppose instead that A had been defined as A[L1..U1][L2..U2][3..5]. How far down the list from the top is A[i][j][3]?

  9. Continuing with the above assumptions, how far down the list from the top is A[i][j][k] for some arbitrary k?

  10. Suppose instead that A had been defined as A[L1..U1][L2..U2][L3..U3]. How far down the list from the top is A[i][j][k]?

  11. Rewrite your answer to the previous questions so that the virtual origin is separated out.

  12. Finally, suppose instead that A had been stored with column-major ordering instead of row-major ordering. How far down the list from the top is A[i][j][k]? Indicate where the virtual origin is in your formula.