What is an array in computer science?
An array is a data structure consisting of a collection of elements (values or variables) of the same data type, each identified by at least one index or key. It is a mutable, linear collection.
What is the simplest type of array?
The simplest type is a linear array, also called a one-dimensional array.
What is an index in an array?
An index (also called a subscript) is a non-negative scalar integer that identifies the position of an element in an array. It maps the array value to a stored object.
What is zero-based indexing?
Zero-based indexing means the first element of an array is indexed by subscript 0.
What is one-based indexing?
One-based indexing means the first element of an array is indexed by subscript 1.
In an array, what is the base address?
The base address (also called first address or foundation address) is the memory address of the first element of the array.
How is the memory address of an element computed in a one-dimensional array?
The address is computed using a formula: base address + (index × size of each element). For example, for an array of 4-byte integers starting at address 2000, element i is at 2000 + (i × 4).
What is a two-dimensional array also called?
A two-dimensional array is sometimes called a matrix, because it can represent a mathematical matrix as a two-dimensional grid.
What is a table in the context of arrays?
A table is often implemented as an array, especially a lookup table. The word 'table' is sometimes used as a synonym for array.
Why are arrays useful for processing many elements?
Arrays allow element indices to be computed at run time, so a single iterative statement (like a loop) can process arbitrarily many elements.
What requirement do elements of an array have?
Elements of an array must have the same size and use the same data representation.
What is an array data type?
An array data type is a kind of data type provided by most high-level programming languages that consists of a collection of values or variables that can be selected by one or more indices computed at run-time.
Name some other data structures that arrays can be used to implement.
Arrays can implement lists, heaps, hash tables, deques, queues, stacks, strings, and VLists.
What is a control table?
A control table is an array used to determine partial or complete control flow in a program, as a compact alternative to multiple IF statements. It is used with an interpreter that changes control flow based on array values.
What is a list in programming?
A list is a data structure that can hold an ordered collection of items. In many languages, lists are dynamic and can grow or shrink, and are often implemented using arrays.
How do you add an item to a list?
You add an item to a list using an operation like 'append' or 'insert', which adds the item at the end or at a specified position.
How do you remove an item from a list?
You remove an item using an operation like 'remove' or 'delete', specifying the item or its index.
What does it mean to iterate over a list?
Iterating over a list means to access each element in sequence, often using a loop, to perform some operation on each item.
What is a two-dimensional table?
A two-dimensional table is a data structure with rows and columns, often represented as a two-dimensional array or a list of lists.
How do you access an element in a two-dimensional array?
You access an element using two indices: one for the row and one for the column, like array[row][column].
When choosing a data structure, what should you consider?
You should consider the type of data and the operations you need: whether the data is ordered, whether you need fast access by index, and whether the size changes.
What is the difference between a list and an array?
In many contexts, a list is dynamic and can change size, while an array has a fixed size. However, in some languages, lists are implemented using arrays.
What is a lookup table?
A lookup table is an array (or table) used to store precomputed values for quick retrieval, often to replace complex calculations.
What is the purpose of using a data structure like a list or array?
Data structures allow you to store and organize multiple values efficiently, making it easier to access, modify, and process data in programs.