You can either create a list of all possible dates between start and end date and then remove dates which appear in the list of given data (works best when most dates are missing), or you can start with an empty list of dates and add ones that don't appear in the given data.
Either way, you basically iterate over the range of dates between the start date and end date, keeping track of where you are in the list of given dates. You could think of it as a 'merge-like' operation where you step through two lists in parallel, processing the records that appear in one list but not in the other. In pseudo-code, the empty list version might be:
# given - array of given dates
# N - number of dates in given array
# missing - array of dates missing
i = 0; # Index into given date array
j = 0; # Index into missing data array
for (current_date = start_date; current_date <= end_date; current_date++)
{
while (given[i] < current_date && i < N)
i++
if (i >= N)
break
if (given[i] != current_date)
missing[j++] = current_date
}
while (current_date < end_date)
{
missing[j++] = current_date
current_date++
}
I'm assuming that the date type is quantized in units of a day; that is, date + 1
(or date++
) is the day after date
.