Data Structures - Arrays
Data Structures
In this article, you'll learn the arrays, the basic data structure and how they work.
Data structures store individual pieces of data and can be accessed in any order. Data structures are useful for electronics and computers, which require storing large amounts of data.
Arrays
The logical or mathematical model of an organization of data is called a data structure. There are many different ways to store and organize data. The data model that you choose will depend on two important considerations. First, it should be rich enough in structure to mirror the actual relationships of the data in the real world. Second, it should be simple so that a request can be processed effectively without any problems.
The simplest type of data structure is a linear (or one-dimensional) array. This means a list of similar data, organized in order from one to n. If we choose the name A for our array, then the elements would be represented by subscript notation.
If we choose the name A for the array, then the elements of A are denoted by subscript notation
a1, a2,a3,….,an
Or by the parenthesis notation
A(1), A(2), A(3), ….,A(N)
Or by the bracket notation
A[1], A[2], A[3], ….A[N]
The number K in A[K] is called a subscript and A[K] is called a subscripted variable.
Parentheses and brackets can be used when the array name consists of more than one letter or when the array is being referenced in an algorithm.
Example
A linear array of six employees with their names (EMPLOYEE) is pictured below.
EMPLOYEE ARRAY
1 2 3 4 5 6 |
Shruti |
John Gold |
|
Gautham |
|
June Kelly |
|
Mary Reed |
|
Tom Jones |
Linear arrays are called one-dimensional because each element in such an array is referenced by one subscript. A two-dimensional array is a collection of similar data elements, where each element is referenced by two subscripts. (Such arrays are called matrices in mathematics and tables in business application.) Multidimensional arrays can be thought of analogously.
Example
A store chain with 24 stores, each of which has four departments, will typically list its weekly sales as in the figure below. Such data can be stored in a two-dimensional array in which the first subscript denotes the store and the second subscript is a department. If SALES is the name given to this array, then
SALES[1, 1] = 2872, SALES[1, 2] = 805, SALES[1, 3] = 3211, …., SALES[28, 4] =982
Dept Store |
1 |
2 |
3 |
4 |
1 2 3 ….. 24 |
2872 2196 3257 …….. 2618 |
805 1223 1017 …… 931 |
3211 2525 3686 ……. 2333 |
1560 1744 1951 …….. 982 |
The size of this table is 24 x 4, which tells us that there are 24 rows and four columns.