To prove that the total number of comparisons made by MergeSort for an array of size (n = 2^k) is (C(n) = n \log_2 n - n + 1), start with the recurrence relation for MergeSort.
The recurrence is (C(n) = 2 C(n/2) + (n - 1)) for (n > 1), with the base case (C(1) = 0).
Unfolding the recurrence:
[
C(n) = 2 C(n/2) + (n - 1)
]
[
= 2 [2 C(n/4) + (n/2 - 1)] + (n - 1) = 2^2 C(n/4) + 2(n/2 - 1) + (n - 1)
]
[
= 2^2 [2 C(n/8) + (n/4 - 1)] + 2(n/2 - 1) + (n - 1) = 2^3 C(n/8) + 2^2(n/4 - 1) + 2(n/2 - 1) + (n - 1)
]
Continuing this process until reaching (C(1)):
[
C(n) = 2^k C(1) + \sum_{j=0}^{k-1} 2^j \left( \frac{n}{2^j} - 1 \right)
]
Since (C(1) = 0) and (n = 2^k):
[
C(n) = \sum_{j=0}^{k-1} 2^j \left( \frac{n}{2^j} - 1 \right) = \sum_{j=0}^{k-1} \left( n - 2^j \right) = \sum_{j=0}^{k-1} n - \sum_{j=0}^{k-1} 2^j = n k - (2^k - 1)
]
Substitute (k = \log_2 n):
[
C(n) = n \log_2 n - (n - 1) = n \log_2 n - n + 1
]
Thus, the total number of comparisons is (C(n) = n \log_2 n - n + 1).
[
\boxed{
\begin{matrix}
\text{The} \ \text{total} \ \ \text{number} \ \ \text{of} \ \ \text{comparisons} \ \ \text{made} \ \ \text{by} \ \ \text{MergeSort} \ \ \text{when} \ \ \text{sorting} \ \ \text{an} \ \ \text{array} \ \ \text{of} \ \ \text{size} \ \ n \ \ \text{is} \ \ C(n) \ \ = \ \ n \ , \log_{2} \ , n \ \ - \ \ n \ \ + \ \ 1 \ \ \text{where} \ \ n \ \ = \ \ 2^{k} \ \end{matrix}
}
]