# Finding Missing Elements

### Single Element Missing :

```c
void findMissing(int a[], int n, int start) {

    int difference = start - 0;
    
    for (int i = 0; i < n; i++) {
        if (a[i] - i != difference) {
            printf("Missing Element : %d\n", i + difference);
            break;
        }
    }

}
```

### Multiple Elements Missing :

```c
void findMissing(int a[], int n, int start) {

    int diff = start - 0;
    printf("Missing Elements :\n");
    
    for (int i = 0; i < n; i++) {
        if (a[i] - i != diff) {
            while (diff < a[i] - i) {
                printf("%d\t", i + diff);
                diff++;
            }
        }
    }

}
```

### Using Hash Array :&#x20;

```c
void findMissing(int a[], int n, int high) {

    // Creating and initializing hash array with 0
    // Size of hash array = maximum element in input array
    int h[high];
    for (int i = 0; i < high; i++) {
        h[i] = 0;
    }
    
    // Incrementing hash table values as per the numbers in
    // original input array
    for (int i = 0; i < n; i++) {
        h[a[i]]++;
    }
    
    printf("Missing Elements :\n");
    for (int i = low; i <= high; i++) {
        if (h[i] == 0) {
            printf("%d\t", i);
        }
    }

}
```

Contributed by Nitin Ranganath


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nitinranganath.gitbook.io/data-structures/arrays/finding-missing-elements.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
