0% found this document useful (0 votes)
10 views

ARRAY

Uploaded by

akhtarsaad89
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
10 views

ARRAY

Uploaded by

akhtarsaad89
Copyright
© © All Rights Reserved
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/ 24

What is an Array?

An array is a type of linear data


structure that is defined as a
collection of elements with same or
different data types. They exist in
both single dimension and multiple
dimensions. These data structures
come into picture when there is a
necessity to store multiple elements
of similar nature together at one
The difference between an array index and a memory
address is that the array index acts like a key value to
label the elements in the array. However, a memory
address is the starting address of free memory available.
Following are the important terms to
understand the concept of Array.

 Element − Each item stored in an array is


called an element.
 Index − Each location of an element in an
array has a numerical index, which is used to
identify the element.
Syntax
data_type
array_name[array_size];
Basic Operations in Arrays
The basic operations in the Arrays
are insertion, deletion, searching,
display, traverse, and update.
These operations are usually
performed to either modify the
data in the array or to report the
Basic operations supported by an array.

Traverse − print all the array elements one


by one.
Insertion − Adds an element at the given
index.
Deletion − Deletes an element at the given
index.
Search − Searches an element using the
given index or by the value.
Update − Updates an element at the given
index.
Display − Displays the contents of the
array.
Insertion operation
in the insertion operation, we are
adding one or more elements to
the array. Based on the
requirement, a new element can
be added at the beginning, end,
or any given index of array. This
is done using input statements of
the programming languages.
INSERTION
An algorithm to insert elements
into a Linear Array until we reach
the end of the array

 1.Start
 2. Create an Array of a desired data type and size.
 3. Initialize a variable 'i' as 0.
 4. Enter the element at ith index of the array.
 5. Increment i by 1.
 6. Repeat Steps 4 & 5 until the end of the array.
 7. Stop
OUTPUT
Array Before Insertion:
 LA[0] = 0
 LA[1] = 0
 LA[2] = 0
 Inserting elements.. Array After Insertion:
 LA[0] = 2
 LA[1] = 3
 LA[2] = 4
 LA[3] = 5
 LA[4] = 6
Array - Deletion Operation

In this array operation, we delete


an element from the particular
index of an array. This deletion
operation takes place as we
assign the value in the
consequent index to the current
index.
Array - Deletion Operation
Consider LA is a linear array with N elements and K is a
positive integer such that K<=N. Following is the algorithm to
delete an element available at the Kth position of LA .
ALGORITHM
 1. Start
 2. Set J = K
 3. Repeat steps 4 and 5 while J < N
 4. Set LA[J] = LA[J + 1]
 5. Set J = J+1 6. Set N = N-1
 7. Stop
Output
Array - Search Operation

Searching an element in the array using a key;


The key element sequentially compares every
value in the array to check if the key is present
in the array or not.
Array - Search Operation
Consider LA is a linear array with N elements and K is a
positive integer such that K<=N. Following is the
algorithm to find an element with a value of ITEM using
sequential search.

ALGORITHM
 1. Start
 2. Set J = 0
 3. Repeat steps 4 and 5 while J < N
 4. IF LA[J] is equal ITEM THEN GOTO STEP 6
 5. Set J = J +1
 6. PRINT J, ITEM
 7. Stop
Output
Array - Traversal Operation

Following is the algorithm to traverse


through all the elements present in a
Linear Array
ALGORITHM
 1.Start
 2. Initialize an Array of certain size and datatype.
 3. Initialize another variable ‘i’ with 0.
 4. Print the ith value in the array and increment i.
 5. Repeat Step 4 until the end of the array is
reached.
 6. End
Array - Traversal
Operation
Output
Array - Update Operation

Update operation refers to


updating an existing element from
the array at a given index.
Consider LA is a linear array with N elements and K is a
positive integer such that K<=N. Following is the
algorithm to update an element available at the Kth
position of LA.

ALGORITHM
1.Start
2. Set LA[K-1] = ITEM
3. Stop
Array - Update Operation
output

You might also like