0% found this document useful (0 votes)
25 views11 pages

Arrayoperation (Insertion, Deletion)

Uploaded by

omsingh300710
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)
25 views11 pages

Arrayoperation (Insertion, Deletion)

Uploaded by

omsingh300710
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/ 11

PRESENTATION

ON
ARRAY OPERATION
ambuddha Chakraborty
ONE DIMENSIONAL
ARRAY
It Is An Ordered List, Which
Consist Of A Fixed Number Of
Homogeneous Data Items
(Elements). These Elements Are
Stored In Successive Memory
Locations According To Size Of
Data Type. Array Is Also
Referred As Set Of (Index ,
Value).
CONCEPT STRUCTRE
(index)

A[0] A[1] A[2] A[3] A[4] A[5] A[MAX -


10 5 46 2 100 97 1] ...

Data element
value
INSERT OPERATION
The Insert Operation Is
Performed By Shifting All The
Elements One Position Ahead From
Index i To N-1 Where i Is The
Specified Index For New Element Is
To Be Inserted. And Adding The
New Element To The Array At The
Specified Index Position.
For example,
index for insertion is i=2 and new element is 17
with N=6. the MAX is the size of the array A.

Array before insertion:


… A[N-1]
A[0] A[1] A[2] A[MAX-1]
10 5 46 2 100 97 …

Insert index position

Move All Elements From Insert Index Position I N-1 Towards Right By One
Position
A[0] 1 2 3 4 5 A[6]
A[MAX-1]
10 5 46 2 100 97 …

Insert Index Position


Array After Shifting:

A[0] 1 2 3 4 5 A[6]
A[MAX-1]
10 5 46 46 2 100 97 …

Insert index
position
Shifted elements
Array After Insertion:
Now, insert (store) new data element 17 at given index
position 2:
A[0] 1 2 3 4 5 A[6]
A[MAX-1]
10 5 17 46 2 100 97 …

Inserted element

For Every New Element Inserted The Number


Of Elements I.E N Should Be Incremented By 1. If
N= Max-1 Then Array Is Full And Insertion
Operation Cannot Be Performed As There Is No
Space For New Element In The Array.
DELETE OPERATION
The delete operation will delete the
element at specified element index from
one-dimensional array. The deletion
operation performed by shifting all the
elements one position before from index
i=1 to N-1 where i is the index of
element to be deleted. A[i] = A[i+1], for
all i to N-1 . This shifting causes
overwriting of the said element with
element at next index position.
For example,
For an array N=7 and index position for
deletion is i=3 and maximum array size
as MAX.
rray Before Deletion:
A[0] 1 2 3 4 5 A[6]
A[MAX-1]
10 5 17 46 2 100 97 …

Delete Index Position


Now , Shift All Element From Index 4 To 6 One Position Before As
Below:
A[0] 1 2 3 4 5 A[6]
A[MAX-1]
10 5 17 46 2 100 97 …

Element At Index 3
The Array After The Shifting Backward Is:
rray after deletion:
A[0] 1 2 3 4 A[5]
A[MAX-1]
10 5 17 2 100 97 97 …

Last element of
array

The element 46 is deleted from the array.


After every delete operation the number of
elements N should be decrement by 1. if
array is empty , the deletion operation
cannot be performed .
Thank you

You might also like