# .css-4zleql{display:block;}justjordant  # Day 3 - Array

Jordan Taylor
·Aug 29, 2022·

Subscribe to my newsletter and never miss my upcoming articles

• Array Types
• Resources

Let’s talk about arrays; arrays can be thought of like boxes, almost like a bento lunch box; we can have many different compartments that we have access to; for storing and retrieving data. From a BigO standpoint, we can see where arrays stand from a Time and Space complexity. ## Array Types

With arrays, we can have two different types.

• Static
• Dynamic

One thing to note is that we can have single-dimensional arrays that are static or dynamic and also multi-dimensional arrays that can be static or dynamic.

### Static Static arrays have a fixed size that they can use. Let’s take a look at how we can use static arrays.

``````// Static Arrays
string[] easternStates = new string;

// initializing the array
easternStates = "NY";
easternStates = "FL";
easternStates = "NC";
easternStates = "SC";
easternStates = "NJ";
``````

We can also initialize an array up front as well.

``````string[] westernStates = { "California", "Oregon", "Arizona" };
``````

### Dynamic

Dynamic arrays look the same as single-dimensional arrays, but the array size is not fixed to a given integer. As we saw prior, we can set a static array to size; with dynamic arrays, this is not needed; this is now handled at runtime.

It is good to know that static or dynamic arrays do not differ in time complexity. Specific operations like resize() increase or decreases the size of the Dynamic Array, but in doing so, it needs no extra memory. thus, the time complexity of resizing an array is O(1).

``````ArrayList numbers = new ArrayList
{"thing1", "thing2", "thing3"};

foreach (var i in numbers)
{
Console.WriteLine(\$"element: {i}");
}
``````

### Single Dimension

In computer science, an array data structure is a data structure consisting of a collection of elements, each identified by at least one array index. An array is stored in such a way that the index of each element can be computed from its index tuple by a mathematical formula. The simplest type of data structure is a linear array, also called a one-dimensional array or Sigle-Dimensional Array.

As an example, a single-dimensional array may look pretty familiar because we tend to use them a lot.

``````string[] westernStates = { "California", "Oregon", "Arizona" };
``````

### Multi Dimension

We can think of a multi-dimensional array just like a single-dimensional one but where we stack multiple arrays on one another, giving us rows and columns.

From a mathematical standpoint, these are called Matrix.

In mathematics, a matrix (plural matrices) is a rectangular array or table of numbers, or expressions, arranged in rows and columns, which is used to represent a mathematical object or a property of such an object.

``````int[,] nums = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
public static int GetNum(int i, int j, int[,])
{
return nums[i,j];
}
``````

## Resources

While using arrays, be sure to take a look at your language documentation for best practices for using arrays.

Look at this array data sheet I have made that you can download for free, hope this helps you in your DSA journey; if not, at least I got to make it for you! Array Data Sheet Download link.

Now that we have reviewed arrays, try completing the following questions using arrays.

Two Sum - LeetCode

Arrays - C# Programming Guide | Microsoft Docs

Array data structure - Wikipedia

Multidimensional Arrays - C# Programming Guide | Microsoft Docs

Single-Dimensional Arrays - C# Programming Guide | Microsoft Docs

### Did you find this article valuable?

Support Jordan Taylor by becoming a sponsor. Any amount is appreciated!