Array Flashcards
Creating an array
int[ ] myValue = new int[size]
space complexity: O(n)
time complexity: O(1)
Inserting value in an array
myArray[someIndex] = myElement;
space complexity: O(1)
time complexity: O(1)
Traversing a given array
for (int i = 0; i < myArray.Length; ++i) { // some operations }
space complexity: O(1)
time complexity: O(n)
Accessing a given cell
T myValue = myArray[integerIndex];
space complexity: O(1)
time complexity: O(1)
Searching a given value in an array
for (int i = 0; i < myArray.Length; ++i) {
if (myArray[i] == someValue) break;
}
space complexity: O(1)
time complexity: O(n)
Deleting a given value in an array
myArray[index] = default
space complexity: O(1)
time complexity: O(1)
Creating a multi-dimensional array
// Empty int[ , ] my2DArray = new int[m, n] // where m & n are int for size and optional
// Initialized int[ , , ] myMultiDArray = new int[ , , ] { { {1,2}, {2, 3} } };
space complexity: O(mn…)
time complexity: O(1)
Inserting a value in to multi-dimensional array
array5[2, 1] = 25;
space complexity: O(1)
time complexity: O(1)
Traversing multi-dimensional array
for (int x = 0; x < YourArray.GetLength(0); x++)
{
for (int y = 0; y < YourArray.GetLength(1); y++)
{
Console.WriteLine(YourArray[x, y]);
}
}
space complexity: O(1)
time complexity: O(mn)
Accessing given cell in multi-dimensional array
int myValue = myArray[m, n]
space complexity: O(1)
time complexity: O(1)
Deleting a given cells value in multi-dimensional array
myArray[m, n] = default
space complexity: O(1)
time complexity: O(1)
Searching multi-dimensional array
Must traverse the array searching. (See traversing 2+D arrays)
space complexity: O(1)
time complexity: O(mn…)