? asked in 教育與參考考試 · 1 decade ago

資料結構 major運算

請問以下題目要如何算,要寫成公式?求完整答案

(a)Obtain an addressing formula for the element A[i1][i2] in an aray declared as A[u1][u2]. Assume a row-major representation of the array with one word per element and α the address of A[0][0].

(b)Obtain an addressing formula for the element A[i1][i2] in an aray declared as B[u1][u2]. Assume a column-major representation of the array with one word per element and β the address of A[0][0].

(c)Obtain an addressing formula for the element A[i1][i2][i3] in an aray declared as B[u1][u2][u3]. Assume a row-major representation of the array with one word per element and δ the address of A[0][0][0].

(d)Obtain an addressing formula for the element A[i1][i2][i3] in an aray declared as B[u1][u2][u3]. Assume a column-major representation of the array with one word per element and γ the address of A[0][0][0].

1 Answer

Rating
  • Leslie
    Lv 7
    1 decade ago
    Favorite Answer

    假設宣告 A[u1][u2]([u3]) 是指

    A 的列標 0 to (u1-1), 行標 0 to (u2-1) (且深度標 0 to (u3-1)).

    (您的題目中, array B 應為 array A)

    (a)

    A[i1,i2] 的上面, 有 i1 個列, 共 i1*u2 個元素;

    A[i1,i2] 所在的這一列, A[i1,i2] 的左方有 i2 個元素;

    因此 A[i1,i2] 之前有 i1*u2+i2 個元素,

    所以 answer: alpha+(i1*u2+i2)*1

    (b)

    A[i1,i2] 的左側, 有 i2 個行, 共 i2*u1 個元素;

    A[i1,i2] 所在的這一行, A[i1,i2] 的上方有 i1 個元素;

    因此 A[i1,i2] 之前有 i2*u1+i1 個元素,

    所以 answer: beta+(i2*u1+i1)*1

    (c)

    A[i1,i2,i3] 的上方, 有 i1 個面, 共 i1*u2*u3 個元素;

    A[i1,i2,i3] 所在的這一面, A[i1,i2,i3] 的左側有 i2*u3 個元素;

    A[i1,i2,i3] 所在的這一面的這一深度, A[i1,i2,i3] 的前方有 i3 個元素;

    因此 A[i1,i2,i3] 之前共有 i1*u2*u3+i2*u3+i3 個元素.

    answer: delta+(i1*u2*u3+i2*u3+i3)*1

    (d)

    A 是由深度的從前往後, 一面一面的存, 每一面是按以行為主的方式:

    A[i1,i2,i3] 的前方, 有 i3 個面, 共 i3*u1*u2 個元素;

    A[i1,i2,i3] 所在的這一面, A[i1,i2,i3] 的左側有 i2*u1 個元素;

    A[i1,i2,i3] 所在的這一面的這一行, A[i1,i2,i3] 的上方有 i1 個元素;

    因此 A[i1,i2,i3] 之前共有 i3*u1*u2+i2*u1+i1 個元素.

    answer: gamma+(i3*u1*u2+i2*u1+i1)*1

    (d 的 answer 也可能為 gamma+(i2*u1*u3+i3*u1+i1

    這是說, A 是從左往右, 一面一面的存, 每一面是深度前往深度後的方式)

    Source(s): DS textbooks
Still have questions? Get your answers by asking now.