0% found this document useful (0 votes)
2 views3 pages

insertion n deletion in array

The document discusses the processes of inserting and deleting elements in an array. It explains how to insert a new element by shifting existing elements to make space and how to delete an element by shifting subsequent elements to fill the gap. Examples are provided to illustrate both operations on an array of integers.

Uploaded by

bhavika.joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

insertion n deletion in array

The document discusses the processes of inserting and deleting elements in an array. It explains how to insert a new element by shifting existing elements to make space and how to delete an element by shifting subsequent elements to fill the gap. Examples are provided to illustrate both operations on an array of integers.

Uploaded by

bhavika.joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Module -1

Díscuss fnseion ic aay at a iver


positin.
a new elenent
Insetn means adding
posHion i ohieh iovelveo
at a spectfic
elemets t make Space
arroy tor the ne
shittng
elenet.

For e
A Is aray o size 7 but
Suppose 5 elemento
ie
A is
holding
A {2,3,4 t ,
Represethon:

A 2 3
2 2
the is T,but
Here, the capacty ccupie d
5 positins ate

Now, Insert (2 at psition 2 :


o insert l2 at i ndex Sne
We want
+his posithon is ahady occupied by 4, wwe ne

shift lement t the right,

Steps:
1. start fom
the |ast occupied postim
shifti
( iode 4, Vole ) and slep
Hght to index S.

2 3

2 Move the ele ment at Tndex 3 (4)


to index

2 34
2

More the element at ndex 2(4)


o Inex 3

2
NOo index 2 is ee, So insert 2 in thi

Position
inal aray after in sertom

2 3 |2

2 3
DiscusS Deletion

Delehon aray nvoves


element Fom specitc posiion since wy
have faed size, deleBin vequre8
elemento to he
left to fil
shifhog the left
by the remored element
or ex

Suppose we hve he A wth


capacity nd 6 elements.
A {2, 3, 12., 4, , "}
hy epresetaton
A
3||2
3 L S
Now delete 12
positin 2
need to remOre 12. fom index 2
To maçntan the ay sbuture,
shft
e.
elenents to the left,
sleps:
1 Move he elenent at in dex 3(ie.u)
to index 2 (It w)l delet1 \2
2 utomehcoly)
2
Move. the olement ot index 4 lie 7)
to index 3

2.

Move elenent
to index

2 3
2 3

You might also like