1 / 16

INTRODUCTION OF ARRAY

INTRODUCTION OF ARRAY. Topics To Be Discussed………………………. Introduction Types of array One Dimensional Array Internal representation of one-dimensional array Example 1 Example 2. Array

Download Presentation

INTRODUCTION OF ARRAY

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INTRODUCTION OF ARRAY

  2. Topics To Be Discussed………………………. • Introduction • Types of array • One Dimensional Array • Internal representation of one-dimensional array • Example 1 • Example 2

  3. Array An array is a fine, ordered set of homogeneous elements. By homogeneous we mean that all the elements of the set of same type. By ordered set, we mean that all the element of the set has unique position and can be accesses by referring to its position within the set. So basic properties of array are: • Homogeneity of its elements • Ordering imposed on elements • Finite number of elements.

  4. An array is a set of elements of the same data type represented by a single name. Each individual array element can be referred to by specifying the array name followed by a index or subscript enclosed in brackets. For example marks is A name of array containing n elements, then the individual array element will be Marks[1],marks[2],……………m, MARKS[N]

  5. Types of Arrays There are two type of arrays : Linear Array or One-Dimensional Array : An array in which each elements can be referred by one subscript of index is known as one-dimensional array or linear arrays. One Dimensional arrays are also known as vectors Multi Dimensional Array: An array in which each element can be referenced by more than one subscripts is known as multi-dimensional array. In two dimensional array, each element of the array can be referenced by two subscripts

  6. One Dimensional Array One Dimensional array is a linear data structure in which the position of an element within array can be given by just one index or subscript. For example, if we have 5 students with roll no 1,2,3,4,5 and their marks are 70,80,90,85,75 then with one dimensional array named MARKS is shown in following figure:

  7. INDEX CONTENTS LB 1 2 3 4 UB 5 In this example, the individual elements are identified by MARKS[1],MARKS[2],……… MARKS[5]. The index or the subscript, which identifies the position has values from 1 to 5. 70 80 90 85 75

  8. Lower Bound(LB) Lower bound is the smallest number that an index can have. In this example LB = 1. Upper Bound(UB) Upper bound is the smallest number that an index can have. In this example UB = 5. Length and Size of the Array Length of the array can be obtained by the following formula : Length = UB – LB + 1

  9. In this example Index Set The set of all possible values of index is known as Index Set. Index Set is denoted by I. in this example: I={1,2,3,4,5} Value Set All array elements have some values. The set of values of array elements is known as value set and is denoted by T. In this example T = {70,80,90,85,75} Length = 5 – 1 +1 = 6

  10. Example Consider an array A[105 : 112]. Find the number of elements in this array. Length = UB – LB + 1 = 112 – 105 + 1 = 8

  11. Internal Representation of One-Dimensional array With in computer’s memory array are represent using sequential representation. Address of first element is known as base address and address of other element can be obtained by adding world length to base address. Lo A [1] Lo + C A [2] Lo + 2C A [3] Lo + (I-1)C A [ I ]

  12. Since the elements of an array are stored in successive memory locations, the address of Kth element of an array can be obtained if we know : • Address of the first element of the array. The address of the first element of the array is known as base address denoted by Lo • Number of memory locations required to store one element denoted by C Formula to calculate the address of the Kth element is : Lo + (K - 1)*C If Lower Bound = 1 Lo + (K - LB)*C If lower Bound ≠1

  13. EXAMPLE - 1 Consider A linear array A[16:30]. If Base = 100 and world length = 4 then calculate the address of A[27]. Solution : A [27] = Lo+(K-LB)*C = 100+27-16)*4 = 144

  14. EXAMPLE - 2 Assume that a linear array with LB=1. if address of A{25]=375 and address of A[30]=390, then find the address of A[16]. Solution: Formula for the address of Kth element is A[K] = Lo+(K-LB)*W Given A[25] = Lo+(25-1)*C=375 Lo+24C = 375 A[30] = Lo+(30-1)*C=290 Lo+29C = 290 +5C= -15 C= 3

  15. Lo+24C =375 Lo+24*3=375 Lo+72=375 Lo=375-72 Lo=303 A[16] = ? A[16] = Lo+(K-LB)*W = 303+(16-1)*3 = 303 + 45 = 348

  16. THANKS

More Related