Array Flashcards

1
Q

Creating an array

A

int[ ] myValue = new int[size]

space complexity: O(n)

time complexity: O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Inserting value in an array

A

myArray[someIndex] = myElement;

space complexity: O(1)

time complexity: O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Traversing a given array

A
for (int i = 0; i < myArray.Length; ++i) {
  // some operations
}

space complexity: O(1)

time complexity: O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Accessing a given cell

A

T myValue = myArray[integerIndex];

space complexity: O(1)

time complexity: O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Searching a given value in an array

A

for (int i = 0; i < myArray.Length; ++i) {
if (myArray[i] == someValue) break;
}

space complexity: O(1)

time complexity: O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Deleting a given value in an array

A

myArray[index] = default

space complexity: O(1)

time complexity: O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Creating a multi-dimensional array

A
// 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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Inserting a value in to multi-dimensional array

A

array5[2, 1] = 25;

space complexity: O(1)

time complexity: O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Traversing multi-dimensional array

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Accessing given cell in multi-dimensional array

A

int myValue = myArray[m, n]

space complexity: O(1)

time complexity: O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Deleting a given cells value in multi-dimensional array

A

myArray[m, n] = default

space complexity: O(1)

time complexity: O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Searching multi-dimensional array

A

Must traverse the array searching. (See traversing 2+D arrays)

space complexity: O(1)

time complexity: O(mn…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly