ArticleslgStudy

science

Array (data type)

Array (data type) is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Array (data type) rather than just read about it. In short: In computer science, array is a data type that represents a collection of elements (values or variables), each selected by one or more indices (identifying keys) that can be computed at run time during program execution. Such a collection is usually called an array variable or array value.

Array (data type) — main illustration
Array (data type) — illustration

Key takeaways

  • Array (data type) belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Array (data type) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Array (data type) from memory before moving on to harder problems.

Reference excerpt

In computer science, array is a data type that represents a collection of elements (values or variables), each selected by one or more indices (identifying keys) that can be computed at run time during program execution. Such a collection is usually called an array variable or array value. By analogy with the mathematical concepts vector and matrix, array types with one and two indices are often called vector type and matrix type, respectively. More generally, a multidimensional array (or n-dimensional array) type can be called a tensor type, by analogy with the mathematical concept, tensor. Language support for array types may include certain built-in array data types, some syntactic constructions (array type constructors) that the programmer may use to define such types and declare array variables, and special notation for indexing array elements. For example, in the Pascal programming language, the declaration type MyTable = array [1..4,1..2] of integer, defines a new array data type called MyTable. The declaration var A: MyTable then defines a variable A of that type, which is an aggregate of eight elements, each being an integer variable identified by two indices. In the Pascal program, those elements are denoted A[1,1], A[1,2], A[2,1], …, A[4,2]. Special array types are often defined by the language's standard libraries. Dynamic lists are also more common and easier to implement than dynamic arrays. Array types are distinguished from record types mainly because they allow the element indices to be computed at run time, as in the Pascal assignment A[I,J] := A[N-I,2*J]. Among other things, this feature allows a single iterative statement to process arbitrarily many elements of an array variable. In more theoretical contexts, especially in type theory and in the description of abstract algorithms, the terms "array" and "array type" sometimes refer to an abstract data type (ADT) also called abstract array or may refer to an associative array, a mathematical model with the basic operations and behavior of a typical array type in most languages – basically, a collection of elements that are selected by indices computed at run-time. Depending on the language, array types may overlap (or be identified with) other data types that describe aggregates of values, such as lists and strings. Array types are often implemented by array data structures, but sometimes by other means, such as hash tables, linked lists, or search trees.

History Heinz Rutishauser's programming language Superplan (1949–1951) included multi-dimensional arrays. However, although Rutishauser described how a compiler for his language should be built, did not implement one. Assembly languages and low-level languages like BCPL generally have no syntactic support for arrays. Because of the importance of array structures for efficient computation, the earliest high-level programming languages, including FORTRAN (1957), COBOL (1960), and Algol 60 (1960), provided support for multi-dimensional arrays.

Abstract arrays An array data structure can be mathematically modeled as an abstract data structure (an abstract array) with two operations

get(A, I): the data stored in the element of the array A whose indices are the integer tuple I. set(A, I, V): the array that results by setting the value of that element to V. These operations are required to satisfy the axioms

get(set(A, I, V), I) = V get(set(A, I, V), J) = get(A, J) if I ≠ J for any array state A, any value V, and any tuples I, J for which the operations are defined. The first axiom means that each element behaves like a variable. The second axiom means that elements with distinct indices behave as disjoint variables, so that storing a value in one element does not affect the value of any other element. These axioms do not place any constraints on the set of valid index tuples I, therefore this abstract model can be used for triangular matrices and other oddly-shaped arrays.

Implementations In order to effectively implement variables of such types as array structures (with indexing done by pointer arithmetic), many languages restrict the indices to integer data types (or other types that can be interpreted as integers, such as bytes and enumerated types), and require that all elements have the same data type and storage size. Most of those languages also restrict each index to a finite interval of integers, that remains fixed throughout the lifetime of the array variable. In some compiled languages, in fact, the index ranges may have to be known at compile time. On the other hand, some programming languages provide more liberal array types, that allow indexing by arbitrary values, such as floating-point numbers, strings, objects, references, etc.. Such index values cannot be restricted to an interval, much less a fixed interval. So, these languages usually allow arbitrary new elements to be created at any time. This choice precludes the implementation of array types as array data structures. That is, those languages use array-like syntax to implement a more general associative array semantics, and must therefore be implemented by a hash table or some other search data structure. As a special case, some languages support sparse arrays, in which the subscripts are constrained to a range but there may be elements not assigned a value.

Language support

Type Languages have differing ways of defining an array type. For example, in C, an array is actually a block of contiguous memory, which is essentially treated as a pointer. In such cases, array declarations can decay to pointers:

However, in other languages, such as Java, an array is an actual type. For any type T, it has a corresponding array type T[], which implicitly inherits from java.lang.Object and implements java.lang.Cloneable and java.io.Serializable. Java arrays appear to have a field length, but it is not a real field; it is a built-in property evaluated natively by the arraylength bytecode instruction.

Multi-dimensional arrays

The number of indices needed to specify an element is called the dimension, dimensionality, or rank of the array type. There are two common ways to support multi-dimensional arrays.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Array (data type)

Start with the simplest possible case. Write down what Array (data type) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Array (data type) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Array (data type) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Array (data type)

In research
Array (data type) appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Array (data type) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Array (data type) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Arrays, Composite data types, Data types, so understanding it makes those chapters shorter.
In everyday life
Look for Array (data type) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Array (data type)” →

How to study Array (data type) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Array (data type) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Array (data type) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Array (data type) in simple terms?

In computer science, array is a data type that represents a collection of elements (values or variables), each selected by one or more indices (identifying keys) that can be computed at run time during program execution. Such a collection is usually called an array variable or array value.

Why does Array (data type) matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Array (data type)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Array (data type).

Tags

  • Arrays
  • Composite data types
  • Data types

Keep exploring