Question

Well, the title says it. Does a one-dimensional array have a direction? Or is the direction of a one dimensional array undefined?

Or maybe stated differently: when visualizing a one-dimensional array, should you visualize it top-down or left-right? Or is this arbitrary?

Does it depend on the programming language?

Was it helpful?

Solution 2

Depending on if it's key value pair it could or it couldn't have a direction. If you assign an array like this

a[0]='something'
a[1]='something else'
a[2]='something something else'

Then it definitely looks like it has a direction. Versus something like this

a['foo']='bar'
a[5]='five'
a['a']=1

If you're talking about how the array is actually stored in memory then that's a different story. I can't remember exactly from my CS classes but I'm pretty sure that the data in an array is stored randomly and just terminated with a pointer to the next part of the array. Don't quote me on that though.

OTHER TIPS

If you mean something like is a 1D array a row-vector or a column-vector ? then the answer is it depends.

Matlab, for example, recognises that a 1 x m vector is not the same as an m x 1 vector.

Fortran, on the other hand, does not recognise the distinction.

I'm sure other languages have their own conventions too.

As for mathematics, the usual convention (in the areas I am familiar with) is that vectors are column-vectors.

Take your pick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top