More than 3 dimensions in an array?

J

JB

Hi Folks I've heard this can be done but it's quite difficult. Can anyone
give an example as to how this works?

I'm looking to understand 4 or 5 dimensions (not necesarily to use in code)
mainly to get the concept.

Any pointers appreciated

John
 
M

Malcolm Smith

John

You've played noughts and crosses (or tic-tac-toe) before. It's a two
dimensional game.

You're happy with that concept aren't you?


Now I remember playing at school with three grids in a row. To win you
either win on one grid or get a line running through all three grids, for
example top middle in all three. That then becomes three dimensional
noughts and crosses.

Then it didn't take us long to make that line of three grids a three by
three square of grids. Now we've got four dimensions.


And so on and so forth.


After about half a dozen dimensions our ten year old brains started to
lost grips with the game, but it was fun and our jotters were a complete
mess with grids all over the place.

- Malc
 
J

Jezebel

Not often you need it, but you can dimension an array with dimensions as
needed. Need to be careful about memory usage because you're allocating
memory for the product of all of the dimensions. There's nothing difficult
about it. I once worked on an application that managed data for a fleet of
fishing boats. Data was stored in a massive array:

Dimension 1: vessel (8 boats in the fleet)
Dimension 2: day of the week (1 to 7)
Dimension 3: hour of the day (1 to 24)
Dimension 4: species caught (1 to 4)
Dimension 5: grade (1 to 3)

Dim Catch(8,7,24,4,3)

Kg of B grade tiger prawn caught between 3 and 4 AM on Thursday by vessel 2
= Catch(2,5,3,2,2)

This was 25 years ago. Can't imagine anyone using that kind of code now.
 
M

Malcolm Smith

Particularly not in the North Sea now where's there's bugger all fish and
we're not even allowed to go out anyway.

- Malc
 
J

JB

Yeah but how would the structure look if I were looking at it now?

The three Dimensional array I've used many times before to good effect on
the understanding that I use it like :-
Dim aThreeDim(iNumRows,iNumCols,iNumTables) thats about right yes? so how
does the four or five dimensional thingy work when you get past the number
of tables? Does it go into collections of tables?

J
 
J

Jeff Hall

Does it go into collections of tables?

Of course - and the next dimension would be, say, "types" of "collections"
of "tables" and so on. If it were skyscraper, the "cell" might be a room
and the "table" would be a floor and the new dimension would be the height
of the building, measured in floors.

Maybe your difficulty is that you are trying to visualise (rather than
conceptualise) your n-dimensional array?

A frequent difficulty people have in designing data structures is to get
confused about whether a new dimension is required or simply an extra
element in an existing dimension. One way to define a dimension is to ask
yourself whether all the other dimensions can remain at the same value for
many different values of this dimension.

--------------------------------------------------------------------
Jeff Hall MSc MRICS
Director, Eon Commerce Ltd.
http://www.eon-commerce.com

Software available for you to evaluate before buying...
EasyHTML/Help CHM file Editor for MS Word
http://www.easyhtmlhelp.com
--------------------------------------------------------------------
 
H

Howard Kaikow

Each element in the Nth dimension in an array is a collection of an array
with N-1 dimensions.
 
K

Klaus Linke

so how does the four or five dimensional thingy work when you get past
the number of tables? Does it go into collections of tables?


Hi J,

If you mean "how does it look in my code", Jezebel has answered that one
already.
If you mean, how does it look deep down in the bowels of my computer:
Any array in any dimension must be stored in the one-dimensional memory.
The computer doesn't have much more trouble handling 23 dimensions than 2 or
3.

Say a tick-tack-toe board might look like × o o × × o o × × in memory.
With the information about the number of rows and columns (3×3), the
computer can retrieve any of the nine elements given the row and column
index. Malcolms three-dimensional tick-tack-toe would be 27 elements long, a
4-dimensional version 81 elements, ...

Greetings,
Klaus
 
J

Jezebel

Howard Kaikow said:
Each element in the Nth dimension in an array is a collection of an array
with N-1 dimensions.

Howard! you should set that to music. It scans beautifully. Do you always
program in iambic pentameter?
 
J

Jeff Hall

Klaus

You state the obvious. Well done! Good for you!

The trouble is that Earth-bound "3D" intellects have real trouble getting
beyond the obvious. I am not being facetious when I say this!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top