Data Structure
 Array Definition
 Representation and Analysis
 Single and Multidimensional Array
 Address Calculation
ARRAY
ARRAY
D
Z
P
34
9
7
7
S
3
22
M
ARRAY
[0]
D
Z P S
M
[1] [2] [3] [4] [5] [6] [7] [8]
34
9 7 7
22
[0] [1] [2] [3] [4] [5] [6] [7] [8]
34
9 7 7
22
[0] [1] [2] [3] [4] [5] [6] [7] [8]
Z D S
P
501
503
500
502
ARRAY
Definition:
An array is a finite, ordered and collection of homogeneous data elements.
Array as ADT:
An array is an ADT whose objects are sequence of elements of the same type
and the two operations performed on it are store and retrieve.
ARRAY: TERMINOLOGY
Type: Type of an array represents the kind of data it is meant for. For instance, and array of
integer, an array of character strings.
Base: The base of an array is the address of the memory location where the first element of
the array is located.
Index: All the elements in an array can be referenced by a subscript like Ai or A[i]. An index is
always an integer value.
Range of indices: Indices of array elements may change from a lower bound (L) to an uppar
bound (U), and these bounds are called the boundaries of an array.
Word: Word denotes the size of an element. In each memory location, a computer can store
an element of word size W, say. The word size varies from machine to machine such as 1 byte
to 8 bytes.
ARRAY
W
501
503
500
502
Physical
Memory
Base
[0]
D
Z P S
M
[1] [2] [3] [4] [5] [6] [7] [8]
S K R T
Index
char
C[0:8]
Size=9
34
9 7 7
22
[0] [1] [2] [3] [4] [5]
4
int I[0:5] Size=6
C[l : u]
ARRAY REPRESENTATION
1D
2D
3D
ARRAY REPRESENTATION
1D
A[l : u]
ARRAY REPRESENTATION
2D
A[l1 : u1, l2 : u2]
row1
row2
row3
row4
col1 col5
A[1 : 4, 1 : 5]
ARRAY REPRESENTATION
3D
A[l1 : u1, l2 : u2, l3 : u3]
l1 : u1
l3 : u3
l2 : u2
ARRAY: NO OF ELEMENTS
1D
In an 1D array, A[l:u], the number of elements is given by
(u-l+1)
A[l : u]
ARRAY: NO OF ELEMENTS
2D
A[l1 : u1, l2 : u2]
row1
row2
row3
row4
col1 col5
In a 2D array, A[l:u], the number of elements is given by
(u1-l1+1)(u2-l2+1)
ARRAY: NO OF ELEMENTS
A[l1 : u1, l2 : u2, . . . , ln : un]
In a 2D array, A[l:u], the number of elements is given by
∏
𝑖=1
𝑛
( ui − li +1)
Data Strctures - Array and its representation

Data Strctures - Array and its representation

  • 1.
  • 2.
     Array Definition Representation and Analysis  Single and Multidimensional Array  Address Calculation
  • 3.
  • 4.
  • 5.
    ARRAY [0] D Z P S M [1][2] [3] [4] [5] [6] [7] [8] 34 9 7 7 22 [0] [1] [2] [3] [4] [5] [6] [7] [8] 34 9 7 7 22 [0] [1] [2] [3] [4] [5] [6] [7] [8] Z D S P 501 503 500 502
  • 6.
    ARRAY Definition: An array isa finite, ordered and collection of homogeneous data elements. Array as ADT: An array is an ADT whose objects are sequence of elements of the same type and the two operations performed on it are store and retrieve.
  • 7.
    ARRAY: TERMINOLOGY Type: Typeof an array represents the kind of data it is meant for. For instance, and array of integer, an array of character strings. Base: The base of an array is the address of the memory location where the first element of the array is located. Index: All the elements in an array can be referenced by a subscript like Ai or A[i]. An index is always an integer value. Range of indices: Indices of array elements may change from a lower bound (L) to an uppar bound (U), and these bounds are called the boundaries of an array. Word: Word denotes the size of an element. In each memory location, a computer can store an element of word size W, say. The word size varies from machine to machine such as 1 byte to 8 bytes.
  • 8.
    ARRAY W 501 503 500 502 Physical Memory Base [0] D Z P S M [1][2] [3] [4] [5] [6] [7] [8] S K R T Index char C[0:8] Size=9 34 9 7 7 22 [0] [1] [2] [3] [4] [5] 4 int I[0:5] Size=6 C[l : u]
  • 9.
  • 10.
  • 11.
    ARRAY REPRESENTATION 2D A[l1 :u1, l2 : u2] row1 row2 row3 row4 col1 col5 A[1 : 4, 1 : 5]
  • 12.
    ARRAY REPRESENTATION 3D A[l1 :u1, l2 : u2, l3 : u3] l1 : u1 l3 : u3 l2 : u2
  • 13.
    ARRAY: NO OFELEMENTS 1D In an 1D array, A[l:u], the number of elements is given by (u-l+1) A[l : u]
  • 14.
    ARRAY: NO OFELEMENTS 2D A[l1 : u1, l2 : u2] row1 row2 row3 row4 col1 col5 In a 2D array, A[l:u], the number of elements is given by (u1-l1+1)(u2-l2+1)
  • 15.
    ARRAY: NO OFELEMENTS A[l1 : u1, l2 : u2, . . . , ln : un] In a 2D array, A[l:u], the number of elements is given by ∏ 𝑖=1 𝑛 ( ui − li +1)