The document discusses arrays as a linear data structure that stores a fixed number of elements of the same type in contiguous memory locations. It describes how arrays are declared with a name, data type, and size. Elements in an array are accessed via an index, and common operations on arrays include retrieving, adding, deleting, and inserting elements. The document also explains how arrays are stored in memory and how each operation works.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
109 views15 pages
CC4 Slide - 2 Arrays
The document discusses arrays as a linear data structure that stores a fixed number of elements of the same type in contiguous memory locations. It describes how arrays are declared with a name, data type, and size. Elements in an array are accessed via an index, and common operations on arrays include retrieving, adding, deleting, and inserting elements. The document also explains how arrays are stored in memory and how each operation works.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15
Learn basic concepts about array data structure
Understand how arrays are stored in computer
memory
Know about inserting, deleting and traversing
operations that can be performed on an array Array -is a collection of Homogenous, Ordered and Finite set of elements. -Homogenous implies all elements must be of the same type and have the same structure -Ordered means that elements are organized in sequence. -Finite means that each array contains a fixed number of elements. -is a Linear data Structure -Its data type can be Primitive, Composite or Other Data Types. -In an array the position of an element is identified by a variable called Index.
-The range of values for the index is referred to as Index Set.
-Smallest value in of index is called Lower Bound and
largest Upper Bound.
-Individual elements of an array are identified by Array Name
and Array Index.
-Programming Languages normally use Bracket Notation.
Ex. x[0],x[1], x[2],x[3], x[4]……x[9] intArray = new int[20]
-Before an array is used in a program, it must be declared.
-Compiler reserves necessary storage space for the array on
the basis of declaration
-Declaration specifies array name, data type, and optionally
size Size
-Ex intArray = new int[20]
Array Name Data Type -Storage Structure represents arrangement of data elements in the memory.
-Array is stored in contiguous memory locations.
-Number of storage cells allocated depends on the data type.
-Address of the first element is called Base Address.
Data Type Byte consumed Character 1 Short Integer 2 Long Integer 4 Four Basic Array Operations -Retrieving -Adding -Deleting -Inserting Retrieving -It is also called Accessing -To retrieve an element we must know the Index value -As computer can directly retrieve an element, accessing is very fast. -Ex. X[3] would access the 3rd index. Adding -Adding operation inserts new element in a position specified by the index
-Adding operation is also sometimes referred to as
Assigning.
-If the array already contains some data, the exiting
element is overwritten. -Ex. x[2]= 10 Deleting -Deleting operation removes an existing element with the given index. -To delete x[index], all elements following x[index] are moved one position to the left. -In this way the element to be deleted is overwritten by the element to its right. -Thus, x[index],x[index+1],x[index+2]….. X[n-1] are shifted to the left. Deleting -In this way the element to be deleted is overwritten by the element to its right. -Thus, x[index],x[index+1],x[index+2]….. X[n-1] are shifted to the left. Inserting -It adds new element in a specified position, without replacing any existing element
-The position is specified in terms of index value or
position relative to an existing element. Inserting -Ex. We want to insert element z before x[index] The elements x[index],x[index+1],x[index+2]….. x[n-1] are moved to the right position Array Traversing -Traversing involves accessing and processing an array element exactly once -It is also called Visiting. -To traverse, we set up a loop varying from lower to upper bound. -Ex. Finding the largest element Finding smallest element Computing average of all elements Printing contents on an array