Array





Definition: A collection of elements stored together in a list-like format. There are two main types of arrays:

  1. Static Array: An array whose number of elements cannot be changed (values of elements already in the array can be changed, but nothing can be added/removed/inserted).

  2. Dynamic Array: An array whose number of elements can be changed (elements can be changed, added, inserted, or removed in any way).



Other common names for dynamic arrays:



Basic Dynamic Array Operations:

  1. Adding an element. By default, adding an element to an array places it at the end. If you would like to add it at another location, see operation #2.
  2. Inserting an element. Elements to the right of the insertion location are shifted right one spot.
  3. Removing an element. Elements to the right of the removal location are shifted left one spot.
  4. Changing an element (this one works for static arrays too). The element is simply changed in place. This is commonly referred to as "setting" an element.

Fun Fact: Arrays are indexed. This means that every element within the array has a number to represent its position, which can be used for retrieval of elements. The first element is considered to be at index 0, second element at index 1, third at index 2, and so on. Elements may switch indices due to shifting places from insertion, addition, or deletion of elements as shown above.



Commonly Used In:



Other Similar Data Structures: