Week 2 Flashcards

Data Structures - Arrays & Lists (19 cards)

1
Q

What are arrays?

A

Arrays are collections of elements stored in contiguous memory locations. Zero-based indexed: first element is accessed with index 0.

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

Characteristics of fixed-size arrays?

A
  • Fixed size after initialisation.
  • All elements must be of the same type.
  • Direct memory access allows fast read/write operations.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When would you use fixed-size arrays?

A

When the number of elements is predetermined

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

What are 2D arrays represented as?

A

A grid or table.

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

What are Jagged arrays?

A

Arrays of arrays where each sub-array can have a different size.

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

Jagged arrays vs 2D arrays

A
  • 2D arrays use contiguous memory, optimising access speed.
  • Jagged arrays require additional memory for references but are more flexible.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you access elements of arrays?

A

Using indices: Console.WriteLine(numbers[2]);

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

How do you search and sort arrays?

A

Using in-built methods like Array.Sort() or implemening custom algorithms.
int[] data = { 3, 1, 4 };
Array.Sort(data);

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

How would you adjust the size of an array?

A

Array.Resize(ref array, newSize)

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

How would you find the index of a value of an array?

A

Array.IndexOf(array, value)

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

How can you copy elements from one array to another?

A

Array.Copy(source, destination, length)

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

What is a list?

A

A dynamic array that resizes automatically as elements are
added or removed.
List<int> numbers = new List<int>();</int></int>

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

Key features of lists?

A
  • Resizable collections without manually reallocating memory.
  • Provides higher-level abstraction than arrays.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is Internal Array Resizing

A

When capacity is exceeded, the internal array size doubles, ensuring
efficiency while minimising reallocation overhead.

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

Use cases of lists?

A

For collections where the size can change frequently.

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

What is a Linked List?

A

A node-based structure where each node contains data
and references to the next (and optionally previous) node.
LinkedList<int> list = new LinkedList<int>();</int></int>

17
Q

Characteristics of Linked Lists?

A
  • Memory efficient, especially for dynamic insertions and deletions.
  • Sequential access is slower compared to arrays
18
Q

How are linked list insert/delete operations?

A

Efficient insertion and deletion since only node references are updated.

19
Q

Use case of Linked Lists?

A

For scenarios requiring frequent insertions or deletions at
arbitrary positions.