| The statistical term median can be thought of as the "middle point" of a set of data. To determine a median, we first start with an ordered set of data. For an odd number of data points, the median is simply the middle point. For an even number of data points, the median is the average (mean) of the two middle points. Examples:
- {1, 2, 3, 5, 7} - median = 3
- {1, 2, 3, 6, 7, 8} - median = (3 + 6) / 2 = 4.5
We can think of the median of a set of data as the 1/2 way point which divides our data into a lower and upper half. When there are an odd number of data points, the median point does not belong to either set. If we take the medians of the lower and upper halves of data, we can similarly determine the 1/4 and 3/4 points within our data. (These are also known as "quartiles", see notes section for clarification.) Applying this to the two examples above:
- {1, 2, 3, 5, 7} - median = 3
- {1, 2} - 1/4 point = (1 + 2) / 2 = 1.5
- {5, 7} - 3/4 point = (5 + 7) / 2 = 6
- {1, 2, 3, 6, 7, 8} - median = (3 + 6) / 2 = 4.5
- {1, 2, 3} - 1/4 point = 2
- {6, 7, 8} - 3/4 point = 7
Similarly, we could expand upon this definition to subdivide at the 1/4 and 3/4 points, and find the 1/8, 3/8, 5/8 and 7/8 points, and so on. You are given a int[] data, your set of data points. You are also given an int numerator and an int denominator, describing the data point (as the numerator and denominator of a fraction) you need to find. Your method should return the required data point, based upon the definitions above.
|