• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

3 dimensional array...the 3rd 'dimension'

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Follks,

In a 2 dimensional array, I understand it's about rows and colums:



simillarly, how would we explain a 3 dimensional array? After row and column being accounted for, what does the '3rd dimension' represent?



Hope someone can explain. Thanks.

regards
John
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rows and Columns, as you have found out, represent 2D space co-ordinates.
For 3D arrays*, think of it as a co-ordinate system in three dimensions, e.g. length, width and height, or x, y & z if you will. To visualize this, imagine a rubic cube or a brick. Every point on the cube/brick can be represented by 3 co-ordinates

*Actually, there is no such thing as 2D,3D or nD arrays. It is an array of arrays or array of array of arrays. (Learnt this from Campbell )
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are going into the realms of multi dimensional arrays, at some point you have to stop trying to visualized the dimensions. Yes, you can use the row/col metaphor to visualize a 2d array. You can use x/y/z metaphor to visualize a 3d array. But what if you go into the 4th dimension, 5th? Nth? You have to start trusting the math and not follow your gut. Most human brains don't have the capacity to visualize beyond the 3rd dimension. Smart ones can visualize in 4 dimensions. Beyond that you have to start trusting the math and stop visualizing
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm going back to my analogy for arrays. I think of eggs. I want some way to hold eggs.

So, I think of any array as an egg carton. It is something that can hold eggs. It can be whatever size I want it to be. Some of the spots can be filled, and some can be empty.

So next I think about a grocery store clerk. He doesn't want to carry out each individual carton of eggs. He has an egg crate, which can hold egg cartons. The cartons can be different sizes, and the crate doesn't have to be full. So now he can tell his boss that in the third crated, the ninth egg is broken, or missing, or blue, or whatever.

To get the eggs to the store, you don't want to deliver one crate at a time, so you stack the crates onto a palate. The palate holds crates which holds cartons which holds eggs - now I have a three dimensional array.

The metaphor can be extended to a truck that holds palates, and then a company that owns trucks, and then several companies in a co-op, and then all the co-ops on Earth...

I suppose you could extend it to all the planets in the galaxy and all the galaxies in the universe, and then all the universes in the multi-verse...but now I might be taking the metephor a bit too far.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:So, I think of any array as an egg carton. It is something that can hold eggs. It can be whatever size I want it to be. Some of the spots can be filled, and some can be empty.


@John: Fred's anaolgy of eggs and cartons is great, so if you're already happy with the idea of a 2-D array being rows and columns, presumably you follow the idea of rows and columns of eggs.

Well, a 3-D array is just rows and columns of egg-cartons.

HIH

Winston
 
Jayesh A Lalwani
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the egg carton metaphor is a great way to explain how multi dimensional arrays in Java are really arrays of arrays or arrays

However, it fails when you are modeling a real n-dimension space. Remember in an n-dimension space, things can be physically adjacent to each other, which you cannot visualize with an egg carton metaphor. For example in a 3 dimensional space, something at (10,10,10) is next to something that is adjacent to (10,10,11). It's easy to visualize that if you think of x/y/z coordinates.

However, if you use the egg carton metaphor, you will have to visualize the egg in the 10th row and 10th col in the 10th carton is next to the egg in the 10th row and 10th col in the 11th carton. Say what? eggs in differrent cartons are "next" to each other. How can that be?

Once you go to 4 dimensions, it becomes even more confusin. The egg in the 10th row and 10th column in the 10th carton in the 10th palette is diagonally connected to the egg in the 10th row, 10th col, 11th carton, 11th palette Wha? how did that happen? Now make an algorthim to find the eggs that are perpendicular to these 2 eggs. Help!! I lost my eggs!
 
Bartender
Posts: 5465
212
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An easy example would be:

suppose you're playing chess at ten boards simultaneously. Then you have ten boards, each of which is an 8 by 8 array.
So you woukd have the 3-D array of squares [10][8][8] and square[3][0][1] would mean: square a2 of board nr 4.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jayesh A Lalwani wrote:Now make an algorthim to find the eggs that are perpendicular to these 2 eggs. Help!! I lost my eggs!


In two dimensions, all points that are perpendicular to a line form a line. In three dimensions points perpendicular to a line form a plane. I therefore assume that in four dimensions all point perpendicular to a line form a space, but I cannot imagine that in any way. Even two spaces could be perpendicular to each other (I assume). Help! Please get your eggs out of my head!
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Vajsar wrote:Help! Please get your eggs out of my head!




I think the main problem with "visualising" when it comes to n-dimensional Java arrays is that fact that each element of a dimension is actually a separate array, so the analogy of lines and squares and cubes (which is certainly how I used to visualise them) breaks down.

A 2-D array is actually more like a histogram than a square, and a 3-D is a spiky Christmas decoration, with [0][0][0] being where you attach the string to hang it on the tree (only 51±2 shopping days left BTW, folks).

Winston
 
bacon. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic