Array in Data Structure
Array in Data Structure
GROUP OF COLLEGES
ASSALAM-O-ALAIKUM
Respected teacher and dear students!
INTRODUCTION:
This presentation is presented by:
Alina Ahsan
Andleeb Fatima
Ramsha mehmood
What is array:
Definition:
An array is the simplest type of data structure. It consists of an ordered collection of elements
which are all of the same type. It can be thought-of as a box with multiple compartments in
which each compartment is capable of storing only one data type.
Notation:
Array-name[element-index]
Representation of Linear array in Memory:
An array occupies a continuous block of memory. This memory is divided into equal parts.
Each part of the block represents one elements of the array. Each element of the array also has
a unique memory address. The starting address of array is called the base address of the array.
If base address of the array is known, the address of any element of the array can be easily
computed.
Operation on Array:
Traversing Operation
Inserting Operation
Deleting Operation
Searching Operation
Traversing Operation:
Definition:
In Traversing Operation each element of the array is accessed exactly once for processing.
This is also called visiting of the array.
Algorithm to compute the sum of values of element of a linear array having ten
element.
2) Repeat For C = 0 to 9
4) Print Sum
5) Exit
Inserting operation
Definition:
In inserting operation, new items are added into an array. A new item can be added.
1. at the end of an array without disturbing other elements of the array if there is an empty
element.
2. at some specified location within the array.
Inserting at the End of Array
Consider an array ‘Temp’ having 10 elements with its first three elements
having values as shown below:
Temp
value 66 72 36
0 1 2 3 4 5 6 7 8 9
index
To insert a value 78 at end of the array, the assignment statement is written as:
Temp[3]=78
New values can be inserted in the above array from fourth to tenth element as these elements
are empty.
Algorithm – Insertion at End
Write an algorithm to add 6 values into elements at the end of array ‘Temp’ that has
only four items stored in its first four elements.
1. Start
2. Repeat step-3 to 3 for I=4 to 9
3. Input value in N
4. Temp [I] = N
[End of step-2 loop]
5. Stop
Inserting a value at specified location in an array
A new value can also be inserted at a specified location in an array. To insert a new
value, the values of the existing elements are moved one step forward or backward to
make space for the new value. The following algorithm explains this process.