Two-dimensional arrays

From Computer Science Wiki
Programming basics[1]

Characteristics of a 2d array[edit]

A two-dimensional (2D) array, also known as a matrix, is a data structure that organizes and stores elements in rows and columns. It can be visualized as a table, grid, or a rectangular arrangement of items. Here are some key characteristics of a 2D array:

  1. Structure: A 2D array is essentially an array of arrays, where each element of the outer array is another array representing a row in the matrix.
  2. Dimensions: A 2D array has two dimensions - rows and columns. The dimensions define the size of the array and are often denoted as (m x n), where 'm' represents the number of rows and 'n' represents the number of columns.
  3. Indexing: Elements in a 2D array can be accessed using a pair of indices, typically (i, j), where 'i' is the row index and 'j' is the column index. Indexing usually starts from 0, so the top-left element is at index (0, 0) and the bottom-right element is at index (m-1, n-1).
  4. Homogeneous Data Type: A 2D array generally stores elements of the same data type (e.g., integers, floating-point numbers, or strings). However, some languages or libraries may support heterogeneous arrays that can store different data types within the same array.
  5. Memory Allocation: In some programming languages, 2D arrays can be created with a fixed size, and the memory is allocated in a contiguous block. In other languages or implementations, they can be dynamically sized or created as nested lists or arrays, which can lead to non-contiguous memory allocation.
  6. Operations: Various operations can be performed on 2D arrays, including addition, subtraction, and multiplication (in the case of matrices), as well as traversal, searching, sorting, and manipulation of individual elements. Some languages and libraries offer built-in functions for working with 2D arrays, while others require manual implementation of these operations.
  7. Use Cases: 2D arrays are commonly used in various applications and domains, including computer graphics, image processing, scientific simulations, game boards, spreadsheets, and adjacency matrices in graph theory.

A video[edit]

This video has some references to Java, but it should help you understand the very basics of 2d arrays : https://www.youtube.com/watch?v=nySZfYSVspo

Standards[edit]

  • Construct algorithms using pre- defined sub-programmes, one- dimensional arrays and/or collections.


References[edit]