answersLogoWhite

0


Best Answer

The first element will be 0,0,0 and the last will be 2,1,2.

It's always best to think of multi-dimensional arrays in terms of a one-dimensional array. That is, a 3x2x3 array is really a one-dimensional array of 3 elements (the first dimension), where each element is a 2x3 two-dimensional array, and where each of those 2x3 arrays is a one-dimensional array of 2 elements (the second dimension), where each element is a one-dimensional array of 3 elements (the third dimension). Thinking in these terms makes it much easier to visualise arrays with 4 or more dimensions.

Arrays are always allocated contiguously, one element after the other. So the memory layout for your three dimensional array is as follows (where 000 means element 0,0,0):

{{000, 001, 002}, {010, 011, 012}}, {{100, 101, 102}, {110, 111, 112}}, {{200, 201, 202}, {210, 211, 212}}

The curly braces are merely notational, but they help to visualise the layout more clearly, dividing the memory into three groups of two groups of three elements. However, if we stack the three main groups one above the other it will be much easier to see visualise the structure:

{000, 001, 002}, {010, 011, 012} {100, 101, 102}, {110, 111, 112}

{200, 201, 202}, {210, 211, 212}

If you look at each row you can clearly see that the first digit in each element is the same throughout that row. However, each row is really a two-dimensional array (of 2x3 elements), so each row is really a 2x3 table. The top row is therefore table 0, the middle row is table 1 and the bottom row is table 2. Let's look at table 0 more closely:

Table 0:

{000, 001, 002}, {010, 011, 012}

Now let's stack the table's 2 elements so we can see the table more clearly:

Table 0:

{000, 001, 002}

{010, 011, 012}

Now the rows are identified by the second digit, where the top row is row 0 and the bottom row is row 1. Each row has three elements and the third digit identifies the column of that element (0, 1 or 2). Here's the complete structure:

Table 0:

Row 0: {000, 001, 002}

Row 1: {010, 011, 012}

Table 1:

Row 0: {100, 101, 102}

Row 1: {110, 111, 112}

Table 2:

Row 0: {200, 201, 202}

Row 1: {210, 211, 212}

From this we can clearly see that we can refer to any individual element through a table identifier (0, 1 or 2), a row identifier (0 or 1) and a column identifier (0, 1 or 2). Therefore to initialise this structure, we need to cycle through each identifier in turn. Here's how we do that using pseudo-code:

given array A [3,2,3]

for each table in 0 to 2

for each row in 0 to 1

for each column in 0 to 2

initialise A [table, row, column]

next column

next row

next table

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How will you initialize a three-dimensional array thread 323. How will you refer the first and last element in this array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How does one initialize a byte array in Java?

One can get information about how to initialize a byte array in java on the website stackoverflow dot com. That website can learn one a lot about java.


How do you set the null value in array?

Depends on the programming language, some languages may have already initialize an array with null (or the default value of the type), some of them require explicitly assignments by stepping through each element of that array, and assigning them with null. (imperative languages)


How do you use arrays in biginteger?

In Java, you would create an array of type BigInteger, then initialize each object (each array element) with the newoperator. I believe it would be something like this: BigInteger[] myArray = new BigInteger[5]; for (int i = 0; i


Which condition is not necessary in dynamic stack?

in dynamic stack we don't have to initialize the size of array while in static stack we have 2 initialize it ......


How you can initialize an array with data values during declaration?

int myArray[] = {1,2,3,4,5};


Which Array tasks are recommended when replacing a hard drive?

Initialize and remove dead segments


Why can't we increment an array like a pointer?

once we initialize the array variable, the pointer points base address only & it's fixed and constant pointer


What is an error in java?

An error or more commonly known as an Exception is a situation where the java program behaves in a way it is not supposed to do so. It is a problem in the code that is causing the JVM to terminate or throw error messages in the console. Ex: When you initialize an array list with 10 elements and try to access the 11th element in the array list you will get an array index out of bounds exception.


How will you initialize a 2-d array?

All arrays are one-dimensional. A two-dimensional array is simply a one-dimensional array of one-dimensional arrays: int a[2][3]; This is an array of 2 elements where each element is itself an array of 3 integers. In other words it is an array of 6 integers. The two dimensions simply allow us to split the array into two sub-arrays of 3 elements each.


What is the default value of the array elements in an integer array?

'0' Try this: public static void main(String[] args){ } The output would be 0 even though you did not initialize any value in the int array.


Will an array element be deleted when you retrieve it from the array?

You cannot delete from an array.


What is Jagged Array in C?

A Jagged array is an array of arrays. You can initialize a jagged array as − int[][] scores = new int[2][]{new int[]{92,93,94},new int[]{85,66,87,88}}; Where, scores is an array of two arrays of integers - scores[0] is an array of 3 integers and scores[1] is an array of 4 integers.