Reference no: EM133658982
Problem
A research team in oceanography has a probe that sends back temperature readings at regular time intervals. Unfortunately, they think the probe is faulty: not only does the team not know how "regular time intervals" is supposed to be defined, but they think some of the measurements haven't been transmitted and are therefore missing from the received data.
The input to your algorithm will be an array A of of measurement times. For simplicity, we will assume each time is a non-negative integer. If the measurements don't exclude any data, then the array A will be of the form [a1, a1 + c, a1 + 2c, . . . , a1 + (n - 1)c], where A has length n (for n ≥ 2) and c is the (constant) time interval between two consecutive measurements. However let us suppose the probe failed to send k measurements, but that neither the first nor the last measurement were skipped. For example, the missing measurement times in [3, 6, 12, 18, 24, 27] might be 9, 15 and 21.
1. How to clearly explain why if you know the value of k, then you can determine the value of c?
2. Give an example f(K) that shows that if you are not told what k is, then you can not determine c, no matter how many values of the array you are given.
3. What if you are not told k, but you are given an upper bound K on its value. You will be able to determine c and k as long as the array you receive contains at least f(K) values. What is f(K), and why?
4. How to clearly describe an algorithm to compute the values of c and k, assuming you know K and are given an array with at least f(K) values?
5. What if you are told what k is. How to clearly describe an efficient algorithm that takes as input the array and the value of k, and returns an array containing all the missing values.