23

doesn't have any tag guidance or tag wiki. It simply denotes an array inside another array, without regard to the size or type of elements. One has to note that these concepts have minor differences in different programming languages.


Some proposals:

Synonymize to

In common parlance, [multidimensional-array] would mean arrays with more than one dimension. But, some users have voiced an opinion in the comments that a multi-dimensional array is one where all elements in each dimension are equal and [arrayofarrays] is different and similar to [jagged-arrays]. Again, the restriction to uniformity in arrays doesn't seem to be the same in all languages.

...many languages simply don't make the distinction between jagged arrays and multidimensional arrays at all....So the real problem here is that the term "multidimensional array" itself is overloaded — languages can't even agree on what constitutes an array, let alone a multidimensional one, but when it comes to nesting them the vast majority of languages seem to prefer calling them "multidimensional" over "nested" or "jagged" (probably because it sounds cooler).
- BoltClock on Why does tag "nested-array" point to "multidimensional-array"?

Synonymize to

A jagged array is sometimes called an "array of arrays."
- Tag wiki of Jagged arrays

In computer science, a jagged array, also known as a ragged array, is an array of arrays of which the member arrays can be of different lengths
- Jagged arrays, Wikipedia

While the term "array of array" maybe used to denote a jagged array, it is not wrong to use it to denote a multi-dimensional array in common parlance.

Burn and use the generic instead

This tag isn't even needed as a generic arrays tag is more than enough.


Can we as a community get a consensus on what to do with this tag?

13
  • 7
    No they do not refer to the same thing. An array of arrays doesn't need to have each inner array be the same size. Jul 6, 2022 at 14:47
  • 1
    I might have an array that has mixed object types, some, perhaps many/most, being arrays, but also composed of other types of objects. Should be careful here.
    – ouflak
    Jul 6, 2022 at 14:50
  • 2
    Jagged arrays is a valid synonym. Jul 6, 2022 at 15:08
  • 2
    I would burninate the arrayofarrays tag after ensuring the question has a arrays tag. If it was kept, it should be repunctuated to the modern (more readable) style: array-of-arrays. Jul 7, 2022 at 13:02
  • @JonathanLeffler Wouldn't a merge([arrayofarrays]=>[arrays]) be more appropriate then?
    – TheMaster
    Jul 7, 2022 at 13:53
  • 2
    kick [arrayofarrays] to another dimension?
    – drew moore
    Jul 7, 2022 at 14:45
  • 1
    Burninate [arrayofarrays] since there are already the other tags covering "rectangular" and "non-rectangular" multi-dimensional arrays for the more specific cases.
    – Drew Reese
    Jul 7, 2022 at 17:42
  • There are multi-dimensional arrays, and then there are arrays-of-arrays. They're two different things. A jagged-array is an array-of-arrays, but not all arrays-of-arrays are jagged-arrays. All this to say, if we get rid of array-of-arrays, we need to replace it with something like "square-arrays" to differentiate from jagged-arrays. Alternatively, get rid of all array variation tags and just use "arrays".
    – Blue Dev
    Jul 8, 2022 at 14:22
  • @BlueDev I'm guessing the definitions you used is for [java]?
    – TheMaster
    Jul 8, 2022 at 15:02
  • @TheMaster I just used general-use definitions, rather than language-specific... if this question is language-specific let me know, it seemed more about S/O than anything.
    – Blue Dev
    Jul 8, 2022 at 16:11
  • @BlueDev That's the thing. It's not language specific. You have three different answers all differing on the definitions of those terms. You say [jagged] is a subset of [arrayofarrays], but the highest voted answer currently says they're the same and should be synonymized.
    – TheMaster
    Jul 8, 2022 at 17:15
  • @TheMaster Sure, the highest-voted answer says we think of them as being the same, but they really are not. A jagged array is named after the fact that some of the arrays inside are "bigger" or "smaller" than others, giving it a "jagged" description. An array of arrays is not necessarily so, and can have every array be the same size, being therefore not jagged but what is often called "square". Check out this comment for a good visualization of a jagged array.
    – Blue Dev
    Jul 8, 2022 at 17:28
  • @BlueDev Would you like to add a answer?
    – TheMaster
    Jul 8, 2022 at 18:01

4 Answers 4

27

Based on reviewing the existing tags, a is a unique data structure which is always square rectangular and may have different syntax.

While few of us encounter the term regularly, appears to be what most of us think about when dealing with an .

Given that has 561 questions and only has 78, and given that is mentioned in the wiki as a synonym, I vote to Synonymize to .

5
  • 2
    I initially felt that [arrayofarrays] was more of a superset of both of the given tags, but after looking into it a bit more I fully agree with you; [jagged-arrays] and [arrayofarrays] are basically always the same thing as far as I can tell. Multidimensional arrays exist as a standalone structure in at least a few languages, and that makes it distinct enough in my head to warrant a tag. But if [jagged-arrays] stays around, I agree it makes sense for [arrayofarrays] to become a synonym of it.
    – zcoop98
    Jul 6, 2022 at 21:57
  • 1
    I don't see the restriction about multidimensional-array being cubic. I tend to agree with Tyler about jagged being a vague term. I read through the wiki of multidimensional array and it doesn't restrict itself to cubic arrays. It actually mentions ""array of arrays" (also known as jagged arrays or Iliffe vector)." so I would say that maybe jagged arrays could a synonym for that, but for starters maybe arrayofarrays is better as a synonym to multidimensional-array
    – Tomerikoo
    Jul 7, 2022 at 7:27
  • 1
    This would be technically incorrect at least for C and C++.
    – Lundin
    Jul 7, 2022 at 7:59
  • 1
    is a unique data structure which is always square. Personally speaking, I would be more convinced if you had a authoritative reference on this restriction as a definition of multi dimensional array, in a wide variety of languages.
    – TheMaster
    Jul 7, 2022 at 17:31
  • 1
    The dimensions of a multidimensional array don't have to have the same size, so they are rectangular rather than square. Jul 7, 2022 at 17:37
23

Maybe I'm in the minority (I do not have a Computer Science degree, but then again most programmers don't, either), but I have never heard the term 'jagged array' before so I would not know to search for it when looking for that kind of thing via tags. "Array of arrays" is self-explanatory even without knowing special terms. What is the reasoning behind the name "jagged" for arrays of arrays? What is "jagged" about them?

That being said, I'm not sure we need a tag for either of them... just use .

8
  • 6
    A jagged array is an array of arrays of different lengths: so they are jagged rather than flat or rectangular.
    – khelwood
    Jul 6, 2022 at 16:01
  • 6
    Jagged arrays are arrays that are not square. They can have variable dimensions e.g. {{1}, {2,3,4}, {5,6}} (hence jagged). In that regard array of arrays describes a more general concept as not all "array of arrays" are "jagged arrays" though all "jagged arrays" are "array of arrays".
    – Henry Ecker Mod
    Jul 6, 2022 at 16:01
  • 2
    I've never heard "jagged array" either but I presume it's an array of arrays where the sub-arrays have differing lengths (jagged) compared to a more "square" shape which apparently is what "multidimensional-arrays" are, not that I'd ever heard that restriction for that term either. Jul 6, 2022 at 16:01
  • 2
    I remember the term being introduced with Java in the mid 1990s (Perl already had them, but with a different name). I could be wrong. Jul 7, 2022 at 1:45
  • 2
    It goes way back. K&R C in the 1970s mentions multi-dimensional arrays vs arrays of pointers (not calling them "jagged" though), claiming that a arrays of pointers were more useful because of flexibility. This was however some 20 years before the advent of cache memories and 30 years before C got variable-length array support.
    – Lundin
    Jul 7, 2022 at 8:24
  • 2
    Sounds like a term tailor made for memorization exams
    – Kevin B
    Jul 7, 2022 at 14:30
  • 1
    For what it's worth, I do have a computer science degree but never heard of "jagged arrays" either. I would also have had no idea what it is supposed to mean without looking it up (maybe it's more obvious for an English native speaker).
    – luator
    Jul 8, 2022 at 11:18
  • 2
    Today, I saw a question about "Jaggered Arrays". Was that a typo, or was it referring to arrays with big, bulging lips, a 50+ year career in rock music and an (alleged) opioid habit? Jul 8, 2022 at 11:48
6

Looking at formal definitions in the languages C and C++, there is very strictly speaking no such thing as multi-dimensional arrays. These languages only have arrays of arrays. These are always "square-shaped" matrices.

A jagged array can be achieved with a pointer table, where each pointer points at an array with individually set size. This is an entirely different kind of data type.

In normal engineering jargon, the term multi-dimensional arrays is what's commonly used and then it refers to an array of arrays.

It's technically incorrect to say that a jagged array is an array of arrays in C and C++, because it is actually an array of pointers. Or in case of C++ containers, it could be a vector of pointers, a vector of vectors etc.

Technical details and explanations can be found in my answer here: Correctly allocating multi-dimensional arrays


Summary for C and C++ specifically:

7
  • (FWIW, I have gold badges for C, C++ and arrays)
    – Lundin
    Jul 7, 2022 at 8:03
  • As a gold badge holder in arrays, do you have a opinion outside of [c], [c++]?
    – TheMaster
    Jul 7, 2022 at 8:07
  • 2
    @TheMaster Not really an expert beyond those languages, but as far as I know these definitions seem to hold fairly well in most languages. Some Java or C# guru might disagree since the array type in those languages is a class (whereas C++ is an OO "hybrid" language) and each item has could have an individual size. At any rate, it should be sufficient for this discussion that the synonym between arrayofarrays and jagged-arrays does not hold for two major programming languages.
    – Lundin
    Jul 7, 2022 at 8:16
  • Isn't a multidimensional-array in C just a single array with convenience syntax to access its square dimensions via multiples of each dimension? Internally it's just a 1-dimensional array with size created by multiplying the two dimensions. It's not an arrayofarrays. The pointer table would be an arrayofarrays (which could be jagged) Jul 7, 2022 at 16:42
  • @DanielWiddis Not really, you dereference the first array of arrays, then dereference the array item you got as result, one dimension at a time. C also allows so-called "mangled arrays" which is just a single dimension 1D array of items but you access it as array[n*i + j]. Whereas the array of arrays array[i][j] was informally named multi-dimensional array by Kernighan & Ritchie back in the early 1970s.
    – Lundin
    Jul 8, 2022 at 6:19
  • The key here is that C is close to the metal, so an array of arrays is not just a 2D array but also the physical representation of the memory layout of its members. While higher level languages could allocate their 2D array items all over the place, which is similar to the array of pointers in C.
    – Lundin
    Jul 8, 2022 at 6:21
  • @Lundin now I think we need a mangled-arrays tag. :) Jul 8, 2022 at 7:18
3

In my mind, a nested array where the inner arrays all have the same size is a "matrix", and a "nested array", "array of arrays" and "multidimensional array" are all synonyms. I've never heard of calling non-matrix nested arrays "jagged arrays" but I am hard-pressed to think of a better name for it if we needed to specify that I need my nested arrays to have varying lengths.

We don't generally have consistent terms for the difference between a (non-nested) variable length array and a (non-nested) array with its length in its data type. With non-nested arrays, in my anecdotal experience it only even comes up in languages that are pretty low-level (e.g. C++), most of them seem to have variable-length collection objects and distinguish between buffer-backed or linked-list-backed implementations for the efficiency profile.

(I more frequently run into the distinction between homogenous collections and heterogenous collections, but that's not very relevant here. Heterogeneity itself brings the requirement of dealing with various sizes in one way or another.)

I realize that this question is about the nested ones specifically, but I bring it up because by default, if I make a nested array from typed-sized arrays I'll get a matrix (and in such a language I'll have to grab a variable-length array-like object and nest that if I want variable lengths), and in most other languages nested arrays are "jagged" by default simply because "arrays" are variable-length by default… and there isn't a debate that I've heard of in the non-nested case about cross-language consistency for naming true arrays versus variable-length array-like objects.

Granted, we do have terms for that when we need them: "collections", "lists", sometimes "vectors" (though that's also just a more math-ey name for an array, list or one-dimensional matrix). That said: firstly, which term to use typically depends on the one chosen to name the types in any given language's library, and second, even though we do have these words I seldom use them specifically to say "this thing isn't a true fixed-size array". I often use "array" and "list" interchangeably to mean any collection, unless and until the difference actually matters.

In other words it feels weird to me to have to specifically call out "jagged" nested arrays as "jagged" for the same reason that I don't call most lists "variable-length array objects" even though I've worked in languages where "true" arrays are fixed-size.

Where does that leave us with what to do with "nested array" and "array of arrays"? "Nested array" has already been decided to point to "multidimensional array", which makes sense to me personally although there's some debate on the desirability there. Consistency suggests "array of arrays" should be the same, although we could always change "nested array" while we're resolving "array of arrays". Theoretically a case could be made for separating out "matrix" for non-jagged arrays, if that helps anything.

"Jagged arrays" isn't a great term for general nested arrays, or really understandable at all, unless you already know you're talking about nested arrays. At first glance it looks like the plural of "a jagged array" – which doesn't have an obvious meaning. Once you think of multidimensional or nested arrays the meaning of "jagged" is obvious, but "jagged arrays" doesn't really spell out that it's multidimensional unless you already know how they are "jagged". Chicken and egg knowledge problem.

Perhaps three categories: matrices, nested / multidimensional / array-of arrays, and jagged – with the middle being synonyms of each other and a superset of the other two, and use "matrices" and "jagged arrays" only where the non-jaggedness of matrices or the non-matrix-ness of jagged arrays is directly relevant?

1
  • 1
    Not important, but I'm surprised the question isn't titled "Should we unnest [arrayofarrays]?" or perhaps "Should we nest [arrayofarrays] and {insert proposed tag here}?" I don't know which to suggest as an edit (if Stack Overflow will even let me at my level of rep)! Jul 8, 2022 at 21:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .