Introduction:
I go through different things people comes searching to my website and recently I found out this new term named ragged and jagged list. I wasn't familiar with the term, so I read about it and going to talk about it from different language and usage perspectives in this article. So by the end of this article, you should be a master of the concept called "ragged or jagged array".
Definition:
A ragged array, also called jagged array, ( yes they are two same things), is basically a non-uniform array, which consists of different length lists as elements. For example, [[1],[1,2,3],[2,5]] is a jagged array.
The name arises from the concept that if you list the elements down one by one vertically, then the edge will be ragged/jagged.
How to create:
In python, it can be quite simple to create. You can just take an empty list []; and then keep pushing different lists one by one using append. For getting a better idea, read about python lists.
For java, read it from geeksforgeeks how we are creating jagged arrays.
Confusions?
One confusion I saw over internet is that, whether this is strictly a 2d array thing. But no. By definition, your elements of the highest level array has to be not of same length. That doesn't mean you can't have more than 2 dimensions.
Conclusion:
So, that was about ragged and jagged array. Didn't know why people were searching for it as it seems to be a pretty simple concept.
Comments
Post a Comment