---
title: "Insertion and deletion in array list"
subject: "Data Structure and Algorithm"
chapter: 3
key: "semester_4/data_structure_and_algorithm:array-list-insert-delete"
source: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/array-list-insert-delete
site: BCT Engineering
---

# Insertion and deletion in array list

Data Structure and Algorithm · Chapter 3: List

- Asked in: 2074 Bhadra, 6 marks
- Video: [Array Insertion and Deletion in C++ | DSA for Beginners](https://www.youtube.com/watch?v=VRdwpF_eJ1k) — Programming Horizons
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/array-list-insert-delete
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-3

## Question

Write algorithms of insertion and deletion of data in array implementation of lists.

## Short answer

Insert: check overflow, shift elements from K to N right, place ITEM at K, increment N. Delete: remove element at K, shift subsequent elements left, decrement N. Example: inserting 25 at position 3 shifts 30,40,50 right, resulting in 10,20,25,30,40,50.

## Answer

In array implementation a list `LA` of `N` elements is stored in `LA[1..N]` (position `1` is the first). The array has capacity `MAX`.

#### Insertion of ITEM at position K

```text
INSERT(LA, N, K, ITEM)
1. if N == MAX:  print "Overflow"; exit
2. if K < 1 or K > N + 1:  print "Invalid position"; exit
3. for J = N down to K:          /* shift right to make room */
       LA[J + 1] = LA[J]
4. LA[K] = ITEM
5. N = N + 1
```

#### Deletion of the element at position K

```text
DELETE(LA, N, K)
1. if N == 0:  print "Underflow"; exit
2. if K < 1 or K > N:  print "Invalid position"; exit
3. ITEM = LA[K]
4. for J = K to N - 1:           /* shift left to fill the gap */
       LA[J] = LA[J + 1]
5. N = N - 1
6. return ITEM
```

#### Example

`LA = 10 20 30 40 50`, N = 5.

- Insert 25 at K = 3: elements 30, 40, 50 move one place right → `10 20 25 30 40 50`, N = 6.
- Delete K = 2: element 20 is removed and 25, 30, 40, 50 move left → `10 25 30 40 50`, N = 5.

Time: O(N) in the worst case for both (insert/delete at the start); O(1) at the end.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Before inserting at position K, what must be checked?
   A. N == MAX (overflow) and valid K (1..N+1)
   B. Only that N is 0
   C. K is even
   D. Array is sorted
   Answer: A. The list must not be full and K must lie between 1 and N+1. (Key point: Insert pre-checks)

2. In insertion, elements from K to N are shifted:
   A. Left, from K upward
   B. Right, starting from the last element
   C. Right, starting from K
   D. Not shifted
   Answer: B. Looping J from N down to K moves each element right without overwriting. (Key point: Shift direction in insert)

3. In deletion at K, elements are shifted:
   A. Right
   B. Left to fill the gap
   C. Not at all
   D. Swapped with the last only
   Answer: B. LA[J] = LA[J+1] for J = K..N-1 fills the gap. (Key point: Delete shifting)

4. What happens to N after a successful insertion and deletion?
   A. Both increase N
   B. Insert N+1, delete N-1
   C. Insert N-1, delete N+1
   D. N unchanged
   Answer: B. Insert adds an element, delete removes one. (Key point: Size update)

5. LA = 10 20 30 40 50, insert 25 at K=3. Result?
   A. 10 20 25 30 40 50
   B. 10 25 20 30 40 50
   C. 10 20 30 25 40 50
   D. 25 10 20 30 40 50
   Answer: A. 30, 40, 50 shift right and 25 takes position 3. (Key point: Example)

## Related in Data Structure and Algorithm

- [Array implementation of list in C](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aarray-list-c-limitations) — Data Structure and Algorithm, chapter 3
- [Static and dynamic data structures; array list](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Astatic-dynamic-ds-array-list) — Data Structure and Algorithm, chapter 3
- [Data types and classification of algorithms](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Adata-types-classify-algorithms) — Data Structure and Algorithm, chapter 1
- [Linear queue using array](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Alinear-queue-array-implementation) — Data Structure and Algorithm, chapter 2, asked 2×
- [Array list; static or dynamic choice](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aarray-list-static-dynamic-reason) — Data Structure and Algorithm, chapter 3
- [Linked list considerations; array list in C](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Alinked-list-considerations-array-list) — Data Structure and Algorithm, chapter 3

## Related in other subjects

- [Adaptive and non-adaptive routing algorithms](https://www.bctengineer.com/question.md?key=semester_8%2Ftelecommunications%3Aadaptive-nonadaptive-routing) — Telecommunications, chapter 8, asked 3×
- [Static and dynamic routing algorithms](https://www.bctengineer.com/question.md?key=semester_8%2Ftelecommunications%3Astatic-dynamic-routing) — Telecommunications, chapter 8
- [Sort array ascending in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-sort-ascending) — Computer Programming, chapter 11, asked 2×
- [CN2 and RIPPER algorithms](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Acn2-ripper) — Data Mining, chapter 3
