This is the pseudocode I used:
Their calculation seems to be different from mine. Can someone explain how they derived it? Here is mine in comparison:
- Line 1: $c_1 \cdot (n-1)$
- Line 2: $c_2 \cdot (n-1)$
- Line 3: $c_3 \cdot n $
- Lines 5-6: $c_4 \cdot \frac{n(n-1)}{2}$ (the if statement executes with an arithmetic progression)
- Line 9: $c_5 \cdot n$
Altogether,
$$T(n) = c_1(n-1) + c_2(n-1) + c_3n + c_4 \frac{n(n-1)}{2} + c_5n,$$
which simplifies to
$$ T(n) = \frac{c_4}{2} n^2 + c_1n + c_2n + c_3n - \frac{c_4}{2} n + c_5n - c_1 - c_2. $$