---
title: "Array implementation of list in C"
subject: "Data Structure and Algorithm"
chapter: 3
key: "semester_4/data_structure_and_algorithm:array-list-c-limitations"
source: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/array-list-c-limitations
site: BCT Engineering
---

# Array implementation of list in C

Data Structure and Algorithm · Chapter 3: List

- Asked in: 2068 Magh, 6 marks
- Video: [Implementation of List using Array](https://www.youtube.com/watch?v=QWxSKSuyKCo) — Wings Lectures
- 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-c-limitations
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-3

## Question

Explain array implementation of list in C with suitable example. What are limitations of this implementation?

## Short answer

A list is kept in an array with a variable count n. Insert/delete shift elements to keep order. Limitations include fixed capacity (overflow/waste), O(n) shifting overhead, contiguous memory requirement, and inability to resize dynamically at runtime.

## Answer

#### Array implementation of a list
A list of elements is stored in consecutive cells of an array `list[MAX]`. A counter `n` tells how many cells are used, so valid elements are `list[0] ... list[n-1]`. Operations: insert at a position (shift right), delete from a position (shift left), traverse, search.

```text
 before insert 25 at index 2        after
 [10][20][30][40][ ][ ]      ->     [10][20][25][30][40][ ]
   0   1   2   3  4  5               0   1   2   3   4  5
```
```c
#include <stdio.h>
#define MAX 10

int list[MAX];          /* contiguous storage */
int n = 0;              /* number of elements currently in the list */

int insert(int pos, int x) {          /* pos = 0..n */
    if (n == MAX || pos < 0 || pos > n) return 0;   /* overflow / bad position */
    for (int i = n - 1; i >= pos; i--) list[i + 1] = list[i];  /* shift right */
    list[pos] = x;
    n++;
    return 1;
}

int delete_at(int pos) {              /* pos = 0..n-1 */
    if (n == 0 || pos < 0 || pos >= n) return 0;    /* underflow / bad position */
    for (int i = pos; i < n - 1; i++) list[i] = list[i + 1];   /* shift left */
    n--;
    return 1;
}

void traverse(void) {
    for (int i = 0; i < n; i++) printf("%d ", list[i]);
    printf("\n");
}

int main(void) {
    insert(0, 10); insert(1, 30); insert(1, 20);   /* 10 20 30 */
    traverse();
    delete_at(0);                                    /* 20 30 */
    traverse();
    return 0;
}
```

Output:
```text
10 20 30
20 30
```

#### Limitations
1. **Fixed size**: MAX must be decided in advance. Too small gives overflow; too large wastes memory.
2. **Costly insertion/deletion**: shifting elements takes O(n) time.
3. **Contiguous memory** is required; a large array may fail to be allocated even if total free memory is enough.
4. **Cannot grow or shrink** at run time without allocating a new array and copying.
5. Poor for lists whose size changes frequently; a linked list is a better choice there.

## Check yourself

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

1. In the array implementation of a list, what does n represent?
   A. Number of cells currently used, so valid items are list[0..n-1]
   B. The maximum capacity of the array
   C. The index of the first free cell after MAX
   D. The value of the last element
   Answer: A. n tracks how many elements are in use; MAX is the capacity. (Key point: Counter n)

2. Why is insertion in the middle of an array list O(n)?
   A. The array must be searched with binary search
   B. Later elements must be shifted right
   C. A new array is always allocated
   D. Each element must be freed
   Answer: B. Shifting up to n elements is needed to make room. (Key point: Cost of insertion)

3. What is the drawback of choosing MAX too large?
   A. Overflow occurs quickly
   B. Insertion becomes O(1) only
   C. Memory is wasted
   D. The list becomes circular
   Answer: C. Unused cells still occupy memory; too small a MAX gives overflow instead. (Key point: Fixed size limitation)

4. Why can a large array fail to be allocated even when total free memory is enough?
   A. Arrays cannot be larger than MAX
   B. Free memory is always pointer-linked
   C. Arrays require a header node
   D. It needs one contiguous block of memory
   Answer: D. Free memory may be fragmented, and no single block may be big enough. (Key point: Contiguity)

## Related in Data Structure and Algorithm

- [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
- [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×
- [Insertion and deletion in array list](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aarray-list-insert-delete) — Data Structure and Algorithm, chapter 3
- [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
- [Linked stack overcoming array demerits](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Astack-linked-overcome-array-demerits) — Data Structure and Algorithm, chapter 4
