Arrays are Amazing!!! | Learning Data Structures with CompAndCode #3

Intro:

Arrays are one of the more simpler data structures out there, meaning they are fundamental to your learning in Computer Science. I'm aiming to simply explain them, provide value and then implement them so that you have an example in code. LETS GO!!!!


Theory:

  • An array is a 'finite, ordered set of elements'.

  • They're denoted by [].

  • This means that the length cannot change, it's predefined.

  • 'Ordered' refers to the fact that each element is indexed, starting from 0.

  • Reference items like this: arrayName[0].

  • The datatype within the array has to be the same for e.g. ["robin", "blackbird"] (all strings).

1D arrays can be visualised as a list of items, simply one after another (shown above).


2D arrays can be visualised as a table.



3D arrays can be visualised like a box (threeDArray[x,y,z])


Python Implementation:

It should be noted that Python doesn't actually have a built in Array feature although this can be implemented with NumPy. For the purpose of this post and to keep things simple, we will just be using Python lists to represent arrays here.


Here's my implementation:



And here's some of the inbuild Python methods you can use, more info here:

Java Implementation:

There are 2 ways to implement Arrays. Ones as 'Arrays' and one as an 'Array List'. Array List allows changes to the length, making it more flexible. See below for both:


Array Approach:

ArrayList Approach:




Final Things:

As always, thank you for making it this far, please leave comments, they help me so much. Be