Use the technical terms associated with arrays

Resources | Subject Notes | Computer Science

Arrays - A-Level Computer Science

10.2 Arrays

An array is a fundamental data structure in computer science used to store a collection of elements of the same data type. These elements are stored in contiguous memory locations, allowing for efficient access using an index.

Key Technical Terms

  • Array: A data structure that stores a fixed-size sequence of elements of the same data type.
  • Element: An individual item within an array.
  • Index: A numerical identifier used to access a specific element in an array. Array indices typically start from 0.
  • Array Bounds: The range of valid indices for accessing elements in an array (from 0 to n-1, where n is the number of elements).
  • Array Size: The total number of elements an array can hold.
  • Declaration: The process of creating an array with a specified name, data type, and size.
  • Initialization: The process of assigning initial values to the elements of an array.
  • Accessing Elements: Retrieving the value of a specific element using its index (e.g., array[index]).
  • Iteration: Processing each element of an array sequentially, often using loops.

Array Declaration and Initialization

In many programming languages, arrays are declared with a specific data type and size. The size is typically specified during declaration. Here's an example in a generic syntax:

data_type array_name[array_size]; 

Arrays can be initialized with values during declaration:

data_type array_name[array_size] = {value1, value2, value3, ...}; 

Array Access

Elements in an array are accessed using their index. The index represents the position of the element within the array, starting from 0 for the first element.

The value of an element at a given index can be retrieved using the array name and the index enclosed in square brackets.

For example, if myArray is an array of integers and myArray[2], it accesses the third element (index 2) of the array.

Array Operations

Operation Description
Access Retrieving the value of an element at a specific index.
Assignment Modifying the value of an element at a specific index.
Iteration (Looping) Processing each element of the array using a loop (e.g., for loop, while loop).
Searching Finding a specific element within the array.
Sorting Arranging the elements of the array in a specific order (e.g., ascending, descending).

Multidimensional Arrays

Arrays can be extended to multiple dimensions to store collections of collections. A two-dimensional array can be thought of as a table of values.

A two-dimensional array is declared with two indices: one for the row and one for the column.

data_type two_dimensional_array[rows][columns]; 
Suggested diagram: A two-dimensional array visualized as a table with rows and columns.

Common Array Algorithms

Arrays are often used with various algorithms. Some common examples include:

  • Linear Search: Searching for a specific element in a linear sequence.
  • Binary Search: Searching for a specific element in a sorted sequence (more efficient than linear search).
  • Sorting Algorithms: Algorithms like bubble sort, insertion sort, merge sort, and quicksort are used to arrange elements in a specific order.