>> Maybe if you are familiar with "Alice" a book that teaches OOP by manipulating "objects" within a 3D enviornment, says an array is like a "collection of boxes... (I assume that they didnt say LIST of boxes for a list can have an item removed and therefore, the lists order is redone) ...that hold objects".
Actually, it calls them a "collection" of boxes because all the boxes aren't necessarily holding the same things. "Collections" are groupings of dissimilar things that serve a common end.
For example, your house holds your dog and your chair, your pot roast and your toilet. Those things aren't the same and they aren't used for the same purposes, but they all serve the common goal of keeping you healthy and happy. Thus, your house is a "collection," because all the things in it are related to a common goal, but aren't related to each other.
The same way your house serves your needs for warmth and shelter by providing a multitude of things that aren't the same as other things in the house, an array can hold dissimilar items -- strings, numbers, dates -- for the purpose of resolving a specific issue.
>> Without pseudocode, or language, could someone explain following their terms of definition, what would a two dimensional look like using the boxes?
"Boxes" is a useful metaphor if you are thinking about how variables and memory in general work. But it's not a useful metaphor when describing data structures, because it's not stacking boxes, so much as it's arranging furniture. So I'll use a house metaphor.
>>I assume one item in a box is one dimensional however, but if more than one item was in a box, is that what is considered multidimensional?
You're on the right track. Again, boxes are the wrong metaphor. Think of your house.
Your house has a kitchen. Inside the kitchen is a refrigerator. Inside the refrigerator is a vegetable bin. Inside the vegetable bin is a tomato. That, in effect, makes your house a 4-dimensional array:
house['room'] ['appliance'] ['compartment'] ['item']
Or, to make it clearer, think of the bureau in your bedroom. It has several drawers, and into each drawer, you have arranged your clothes.
That would be a one-dimensional array: Each drawer is a "box", or a cell of the array; each drawer, or "box," contains one type of clothing.
Let's now turn to your refrigerator.
Most refrigerators have a freezer side and a regular side. Think of those as the first dimension of an array:
Fridge['section'] = new array('freezer', 'refrigerator');
Within the refrigerator section, there are meat and veggie bins:
Fridge['section'] ['compartment'] = new array('shelves', 'meat', 'veggies');
So, the refrigerator side of could be viewed as a two-dimensional array.
Using the box idea, the fridge is a box that contains two side-by-side boxes: freezer and regular. Inside the regular box, there are three more boxes: the shelves, meat bin and veggie bin.
So, to get a tomato, you open the fridge box, then the refrigerator side box, then the veggie bin box, and bingo, a tomato should be in there.
2007-04-27 05:19:51
·
answer #1
·
answered by Anonymous
·
1⤊
0⤋
A two dimensional array can be thought of as a grid. Each square in the grid is a box from your example. To carry the box theme further you can think of ordering a bunch of boxes in a square or rectangular shape.
To access item 4, 3 you would go over four columns and down three rows and that is the item you want.
To move to even more dimensions a 3 dimensional array can be though of a cube cut into smaller cubes. You move on each access of the cube to find the index you are looking for. (Note that visualizing 4 dimensional arrays gets more complex.)
When ever I am having trouble conceptualizing my arrays (for 1-3 dimensions), I find it useful to draw them on grid paper. That is what I recommend for you.
While items can be moved in and out of arrays, the spot remains. You are right in thinking that it is not like a list in this manner. If an item is deleted from an array then that spot is empty (or null). It does not change the addresses (locations) of the other items.
Vaccano
2007-04-27 11:50:54
·
answer #2
·
answered by Vaccano 1
·
1⤊
0⤋
I don't know this Alice thing. However, I do know multi-dimensional arrays.
Think of an array as 1 line of data, like this:
01 02 04 06 08
Here's a 2 dimensional array:
01 02 04 06 08
0A 0C 05 02 00
The 1 dimensional array looks like this in C/C++:
char number;
char myarray[5]=01,02,04,06,08;
I can retrieve the 4th byte like this:
number=myarray[3];
(Remember that with computers, numbers start at 0, not 1.)
To access the 4th number in the 2nd line of the 2 dimensional array, I would do this:
number=myarray[1,3];
The 1st number indicates the line number (row), and the 2nd number indicates the element number in the line (column). Using the example above of a 2 dimensional array, 'number' would equal 02.
2007-04-27 11:51:27
·
answer #3
·
answered by Balk 6
·
0⤊
0⤋
A two dim. array is like the arrangement of boxes at the
post office... or a stack of shoe boxes... or the arrangement
of squares on a chess or checkers board.
A series of rows and columns. You can address each "box"
by giving the unique position using row and column.
Only one box is at row 2, column 3.
A three dimensional array would be like having banks and
banks of 2 dimensional arrays... or layers of chess boards.
You address a particular box by row, column, stack level.
so that a typical address might be: row 4, column 2, stack level 4, or the 4th board up from the bottom.
2007-04-27 12:08:39
·
answer #4
·
answered by bubbadaguy 3
·
0⤊
0⤋
An array is really just a list of variable names you can assign values to. Its power lies in the way you can access the list to manipilate the variable contents. As others have stated, if you were to look at the a two dimensional array graphically, it would look like a spreadsheet, where each co-ordinate (colomn A row 6,etc,) can contain a number, word, letter or phrase.
The power of the array is this:
1. you can define a whole mess of variables in one statement or line. In many 4 GL languages or Basic, this is called Dimensioning an array. a code example might look like this-
Dim(4,3) which would give you the following variable names to attach values to- 0,0 0,1 0,2 0,3 1,0 1,1 1,2 1,3 2,0 2,1 2,2 2,3 3,0 3,1 3,2 3,3 4,0 4,1 4,2 4,3
so you can then set 1,1 = "hello" or 2,3 = "world"
2. An array makes it easy to build programing routines to automaticly add or extract values to the array variables in a loop structure.
A basic programming example:
b=2 X=0 Y=0
For X= 0 to 4
X,Y = b
X= (X=1)
b= (b+1)
Next
the above would set variable 0,0 equal to 2
1,0 equal to 3
2,0 equal to 4
3,0 equal to 5
4,0 equal to 6
Visually, a one dimensional array is a list
a two dimensional array is a grid
a three dimensional array is a cube
Because the array technique names the variables in an orderly way, it makes them very handy to access in mechanical programming structures like the above, or stuff with values from a DATA statement line, so that the DATA elements become Variables with predictable names, if rather dry names. I.E, check-bal= 23.40 is a bit more descriptive than 4,3=23.40.
2007-04-27 13:12:34
·
answer #5
·
answered by inconsolate61 6
·
0⤊
0⤋
A two dimensional array is a table. A spreadsheet is a classic visualization of a two diminsional array. Each cell (box) can be addressed by knowing the Row (1,2,3,....) and Column (a,b,c..).
So practical example might be sales figures by month and year
1 Column for each month (12 columns)
1 row for each year (unlimited rows)
The information in the cell is the gross sales for that month and year
2007-04-27 11:55:29
·
answer #6
·
answered by jehen 7
·
0⤊
0⤋