Number of Comparisons in an Algorithm The number of comparisons in the following algorithm is supposed to be $3n/2 - 3/2$ if $S$ is odd. I understand that the for loop is $3n/2$ comparisons, but I fail to see where the $-3/2$ comes from.
if (n % 2 == 0):
    if (S[0] &gt; S[1]):
        Largest = S[0]
        Smallest = S[1]
    else:
        Smallest = S[0]
        Largest = S[1]
    I = 3
else:
    Smallest = Largest = S[0]
    I = 2

for (i=I; i&lt;=n-1; i+=2):
   if S[i] &lt; S[i+1]:
     if S[i] &lt; Smallest:
      Smallest = S[i]
     if S[i + 1] &gt; Largest:
      Largest = S[i + 1]
   else:
     if S[i + 1] &lt; Smallest:
      Smallest = S[i + 1]
     if S[i] &gt; Largest:
      Largest = S[i]
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}$.