547 views
0 votes
0 votes
A two dimensional array is stored in column major form in memory if the elements are stored in the following sequence $$A[0][0] A[1][0] A[2][0]...A[n_1-1][0] ... A[0][1] A[1][1] ... A[n_1-1][1] .... A[0][n_2-1]...A[n_1-1][n_2-1]$$

The left most index varies most rapidly if we look at the looping changes.

For a particular element $A[i_1][i_2]...[i_m]$ of an $m$ dimensional array $A[n_1][n_2]...[n_m]$ if we denote $e_m$ as the number of elements stored in memory before the given element, we can see the following

$$ e_1 = i_1$$
$$ e_2 = i_1 + i_2 \times n_1$$
$$ e_3 = i_1 + i_2 \times n_1 + i_3 \times n_1 \times n_2$$

How to show that generally

$$ e_m = e_{m-1} + i_m \times \prod_{j=1}^{m-1}{n_j}$$

If we look at the two dimensional array, the number of elements stored before a particular array location can be calculated as the column number of the element we are looking for summing with the $row \times column$ number of elements. How does the above recurrence relation work?

Please log in or register to answer this question.

Related questions

0 votes
0 votes
2 answers
1
1 votes
1 votes
1 answer
3
sripo asked Nov 14, 2018
1,606 views
T(n)=T(n/2)+2; T(1)=1when n is power of 2 the correct expression for T(n) is:a) 2(logn+1)b) 2lognc)logn+1d)2logn+1
3 votes
3 votes
1 answer
4
Ashish Sharma 3 asked Jun 16, 2017
1,758 views
What will be the time complexity for the following recurrence relation?$T(n) = 8\sqrt{n} T(\sqrt{n})+(log n)^{2}$According to me it is $\Theta (n(logn)^{3})$ . Please con...