Number of Comparisons in an Algorithm
If $n$ is odd, no comparison involving elements of $S$ is performed outside of the for loop.
Moreover, each loop iteration performs exactly $3$ comparisons involving some element in $S$. The number of iterations is the minimum integer value of $k$ such that $2+2k &gt; n$, i.e., $k=\left\lceil \frac{n-2}{2} \right\rceil = \frac{n-1}{2}$.
Therefore, the total number of comparisons involving some element in $S$ is $3 \cdot \frac{n-1}{2} = \frac{3n}{2}-\frac{3}{2}$.