Download presentation
Presentation is loading. Please wait.
Published byRosalind Chapman Modified over 8 years ago
1
1
2
2 Introduction Array Operations Number of Elements in an array One-dimensional array Two dimensional array Multi-dimensional arrays Representation of Arrays in Memory One-dimensional array Two-dimensional arrays Three dimensional arrays N-dimensional array Applications Sparse matrix Ordered lists ADT for arrays Outline
3
3 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. Engineering applications usually involve large chunk of data (of common type) Arrays provide easy and efficient concept for data storage or management Arrays are usually processed through loops (processing is very common) Arrays are accessed by indicating an address or index
4
4 Arrays could be of one-dimension, two dimension, three-dimension or in general multi-dimension. ◦ A[1:5] ◦ A[1:5, 1:3] ◦ A[1:3,2:4,5:6,…,a:n] N dimension array: ◦ A[a 0 :b 0,a 1 :b 1,…,a n-1 :b n-1 ]
5
5 An array when viewed as a data structure supports only two operations: ◦ storage of values (i.e.) writing into an array (STORE (a, i, e) ) ◦ r etrieval of values (i.e.) reading from an array ( RETRIEVE (a, i) )
6
6 Or (array’s size), is essential “memory locations” A[l : u] where l is the lower bound and u is the upper bound of the index range, the number of elements is given by (u – l + 1). The size of one dimension array: Upper bound – lower bound + 1 A[l1 : u1, l2:u2] has a size of (u1-l1+1) (u2-l2+1) elements
7
7
8
8 Calculate the size of the following arrays: ◦ A[1:10] ◦ A[-1:2] ◦ A[2:5,2:8] ◦ A[3:4,3:5,1:5]
9
9 The arrays are stored in memory in one of the two ways ◦ row major order or lexicographic order ◦ column major order.
10
10 One dimensional array
11
11 Given the address of the first element is (100), find ◦ In A[1:17] the address of A[7] ◦ In [-2:23] the address of A[16] (106, 118)
12
12 Two dimensional array
13
13 Find : ◦ A[1:10,1:5] the address of A[8,3] ◦ A[-2:4,-6:10] the address of A[3,-5] (257,306)
14
14 Three dimensional array
15
15 A[1:5,1:2,1:3] A[2,1,3] A[-2:4,-6:10,1:3] A[-1,-4,2] ◦ (118,168)
16
16 N Dimensional arrays Let be an N-dimensional array. The address calculation for the retrieval of various elements are as given below:
17
17 Sparse Matrix A matrix is a mathematical object which finds its applications in various scientific problems. A matrix is an arrangement of m X n elements arranged as m rows and n columns. The Sparse matrix is a matrix with zeros as the dominating elements. There is no precise definition for a sparse matrix. In other words, the “sparseness” is relatively defined A matrix consumes a lot of space in memory. Thus, a 1000 X 1000 matrix needs 1 million storage locations in memory. Imagine the situation when the matrix is sparse! To store a handful of non-zero elements, voluminous memory is allotted and there by wasted!
18
18 To save valuable storage space, we resort to a 3-tuple representation viz., (i, j, value) to represent each non-zero element of the sparse matrix. In other words, a sparse matrix A is represented by another matrix B[0:t, 1:3] with t+1 rows and 3 columns. Here t refers to the number of non-zero elements in the sparse matrix. While rows 1 to t record the details pertaining to the non-zero elements as 3-tuples(that is 3 columns), the zeroth row viz. B[0,1], B[0,2] and B[0,3] record the number of non- zero elements of the original sparse matrix A.
19
19 One of the simplest and useful data objects in computer science is an ordered list or linear list. An ordered list can be either empty or non empty. In the latter case, the elements of the list are known as atoms, chosen from a set D. The ordered lists provide a variety of operations such as retrieval, insertion, deletion, update etc. The most common way to represent an ordered list is by using a one-dimensional array. Such a representation is termed sequential mapping through better forms of representation have been presented in the literature. Ordered lists
20
20 Given the following for the array RES. Find the address of RES[17]. ◦ Base address 520 ◦ Index of range 1:20 ◦ Array typeReal ◦ Size of memory location 4 bytes For the following array B compute: ◦ The dimension of B ◦ The space occupied by B in the memory ◦ The address of B[7,2] ◦ Array B Column index 0:5 ◦ Base address 1003 ◦ Size of the memory location 4 bytes ◦ Row index 0:15
21
21 ADT for Arrays Data objects: A set of elements of the same type stored in a sequence Operations: Store value VAL in the i th element of the array ARRAY ARRAY[i] = VAL Retrieve the value in the i th element of array ARRAY as VAL = ARRAY[i]
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.