Merge-sort Algorithm Time Complexity Using Induction
Merge-sort Algorithm is a divide-and-conquer algorithm that works on:
1. Dividing: Recursively dividing the array into two halves.
2. Conquering: Recursively sorting each half.
3. Combining: Merging the sorted halves into a single sorted array.
Time Complexity Analysis:
Base Case: For an array of size 1 or 2, Merge Sort takes constant time, O (1).
Inductive Hypothesis: Assume that for any array of size k, where k < n, Merge-sort takes O ( k*log(k) )
time.
Inductive Step: Consider an array of size n. Merge Sort divides this array into two halves of size n/2. By
the inductive hypothesis, sorting each half takes O ((n/2)*log(n/2)) time. The merging step takes O(n)
time.
Therefore, the total time for Merge Sort on an array of size n is:
T(n) = 2T (n/2) + O(n)
<= 2c (n/2)*log(n/2) + cn
<= cn*log(n) - cn + cn
<= cn*log(n)
where:
c is a constant.
For any array of size n, Merge Sort takes O(n*log(n)) time.