Professional Documents
Culture Documents
Chapter 2
Linear Array
• List of finite number of homogeneous data elements such-
• Elements referenced by index set( of consecutive numbers)
• Stored in successive locations.
• Length =UB – LB + 1
Representation in Memory
• Base(LA) = base or address of 1st element
• No need to save all locations 1000
1001
Limitations
• Dataset needs to be sorted
• Need direct access to middle element
Multidimensional Array
• 2-dimensional array define size m x n.
• Each element specified by a pair of integers (i.e. I & J) such
1≤I ≤m and 1 ≤ J ≤n
• Element of array A : A[I,J] or AI,J
Representation in Memory
2-D array A can be store in memory in 2 ways:
Row-major order:
LOC[A[J,K] =Base(A) +w[N(J-1) + (K-1)]
Here. LB =1
Size of A =M x N
Pointer , Pointer Array
• Variable P is pointer if points to a certain element (contains location
of the element)
• Array Ptr is pointer array if each element points to a certain element
i.e. each one is pointer
• “Vectors” and “matrices” are mathematical terms are analogous,
respectively, to linear and two-dimensional arrays.
• An n-element vector V is a list of n numbers usually given in the form
V= (V1, V2, V3)
• An m X n matrix A is an array of m * n numbers arranged in m rows
and n columns
Matrix Multiplication
MATMUL(A, B, C, M, P, N)
Let A be an M x P matrix array, and let B be a P x N matrix array.
Product of A and B is an M x N matrix as array C
ALGORITHM:
1. Repeat for T=l toM:
Repeat for J = 1 to N:
1.Set C(I, J] := 0
2.Repeat for K = 1 to P:
C[I, J] := C[I,J] + A[I, K] * B[K, J]
[End of inner loop.]
[End of Step 2 middie loop.]
[End of Step 1 outer loop,]
5. Exit.