Arrays Flashcards: Introduction

Updated: Jul 25, 2021

Hi, my name is Nery, I'm a Senior Software Developer and Technical Lead on a quest of refreshing my knowledge on Data Structures and Algorithms. So I decided to create these flashcards with information on key concepts from basic data structures to understanding time complexities and big O notation. These are going to be quick, straightforward, and as simple as I can so everyone, despite their experience, can get a hold of them and find value.

We will begin with Arrays, as they happen to be one of the most important data structures out there and the base structure for other data structures and the primitive type string.


What is an Array?

In simple terms, an array is a linear collection of elements. But, let's deconstruct that definition to understand each bit of it.

Linear: this means that the elements are ordered and stored in neighboring locations in memory (a.k.a, side by side), this makes knowing the location of an element fairly easy.

Collection: a collection is a group of things, in this case, elements.

Elements: the data stored in the collection. This could range from primitive types of the language, such as strings, integers, boolean, or complex types such as classes or structs.

Particularities of an Array

Arrays are homogeneous

This means that even though they could store different types of data, it has to be one at a time. It can either contain integers or strings, even complex objects like classes or structs.

[1, 2, 3, 4] ✓

['Hello', 'World'] ✓

[1, 'Hello', true] ✕

Note: there are ways where you can create dynamic-typed arrays, but if you wish to access specific methods and properties of a certain type, you will need to cast it to that type. When you have multiple types in one array it becomes unpredictable and prone to errors.

Arrays are limited

Arrays have an n limit of elements upon creation. This means that you cannot add more items past the limit of the array, if you do so you will get an index out of bounds exception (the naming may differ depending on the language you're using).

Note: some languages like JavaScript do not fix the capacity of the Array, but actually Arrays in JavaScript are more list-like than array-like, I will expand this in the future.

Arrays are ordered

Don't get confused here, this doesn't mean they are sorted, this only means that they follow a linear structure, meaning elements are placed next to the other in memory.

Properties of an Array

To understand arrays, we must understand concepts such as element, index, and capacity, this information will play a big role when performing operations to an Array.

Element, the actual value stored in a specific location of the array.

Index, an indicator of a specific location on the array. It is zero-based, meaning that the first index in the Array will not be 1, but zero instead.

Capacity, an indicator of the size of the Array and how many elements I can fit in each of the spaces.

Capacity vs Length

No, the capacity of an array does not equal the length.

Capacity is how many elements I can store in my Array. Arrays are limited, meaning they can hold as many elements as you set them to. That will be the capacity.

Length is the number of elements currently in the Array.

I know, I know, in most programming languages you use the .length attribute to check on the capacity of the array. It's confusing, but there's nothing we can do about it but get used to it, bummer!


Thank you for reading!

I have created these as actual flashcards on my Quizlet, so you can quickly access these terms and concepts.