## Invitation to Computer Science 8th Edition

For the positions of the two middle elements in a list with an even number $n$ of elements: $\left[\frac{n}{2} \text { and } \frac{n}{2}+1\right]$ and their average $\left[\frac{n+1}{2}\right]$
We do the same with lists that consist of an even number of elements $n .$ We know that even numbers are divisible by $2 .$ So there isn't just one distinct middle element, but two. The positions of the two middle elements are the required number of comparisons to find them. The average of these two numbers is their sum divided by 2. Example $\quad\bullet$ For $n=16$ the positions of the two middle elements are 8 and $9 .$ $\quad$$\quad Average =8.5 \quadFor n=40 the positions of the two middle elements are 20 and 21 . \quad$$\quad$Average $=20.5$ $\quad$$\bullet For n=56 the positions of the two middle elements are 28 and 29 . \quad$$\quad$Average $=28.5$ The values for the two middle elements can be found using the expressions: $\frac{n}{2}$ and $\frac{n}{2}+1$ Let's find an expression for the average of the two values for the middle elements: $\frac{\frac{n}{2}+\frac{n}{2}+1}{2}=\frac{\frac{2 \cdot n}{2}+1}{2}=\frac{n+1}{2}$