Assignment One

Gabriel Ralph - 470205736

For an array S of unique numbers ordered in such a way that given some number x the order of an element is $S_i = (i + x ) \ \% \ n$ where n is the length. $$ max(S) = S_i \quad and \quad min(S) = S_{i+1} \quad when \quad x + i = n - 1$$

Assumptions

As $n = 0$ and $n = 1$ are trivial cases lets assume $n > 1$

As the module operater will bound $x$ let us assume $x \in (0, n-1)$

It can be seen that $ (x + i) \ \% \ n < (x + i + 1) \ \% \ n \quad when \quad x + i \ne n - 1$

Hence $$S_i < S_{i+1} \quad x + i \ne n - 1$$

$S_0 = x\ \% \ n = x%$

$S_{n-1} = x + n - 1 \ \% \ n=\begin{cases} x - 1 & x \ne 0 \\ n - 1 & x = 0 \\ \end{cases}$

therefore $$S_0 > S_{n - 1} \quad x \ne 0$$ $$S_0 < S_1 < S_2 < ... < S_{max}$$ $$S_{min} < S_{min+1} < ... < S_{n - 1}$$ Hence the values to the left of the largest number are greater than the values to the right.

Consider a subset of S, C such that C includes the largest number:

case 1: $C_0 < C_{n_c - 1}$
This will occur only when the largest value is at the end of the subset and there are no values to right.

Therefore $Max(S) = C_{n_c - 1}$

case 2: $C_0 > C_{n_c - 1}$
If we look at the value in the middle of the subset $C_{mid}$ then the largest value must exist either to the right, left or $Max(S) = C_{mid}$

Consider those cases:

case 1: $Max(S) = C_{mid}$
$C_{mid} > C_0 > C_{n_c - 1}$

$0 > C_0 - C_{mid} > C_{n_c - 1} - C_{mid}$

$C_{mid} - C_{n_c - 1} > C_{mid} - C_0$ or $$|C_{n_c - 1} - C_{mid}| > |C_0 - C_{mid}|$$ Although this suggests that the solution is to the right of the midpoint if the next subset includes the last midpoint then solution will always be included in further itterations and hence this case can be ignored.

case 2: largest number to the left of midpoint
The midpoint is to the right of the solution and $C_0 > C_{n_c - 1} > C_{mid}$ $$|C_0 - C_{mid}| > |C_{n_c - 1} - C_{mid}|$$

case 3: largest number to the right of the midpoint
The midpoint is to the left of the solution and $C_{mid} > C_0 > C_{n_c - 1}$

$0 > C_0 - C_{mid} > C_{n_c - 1} - C_{mid}$

$C_{mid} - C_{n_c - 1} > C_{0} -C_{mid} > 0$ or $$|C_{n_c - 1} - C_{mid}| > |C_0 - C_{mid}|$$
By recursively choosing the half of a subset that contains the solution we will be left with a subset that contains only the largest value and another value. This will occur after $log(n)$ recursive calls as for every call the subset will decrease by half, further more as only a constant number of elements are checked in each call this algorithm will run in $O(log(n))$ time.