I’m reading my algorithms text book, and I’m reading about recurrence relations and finding the algorithms big O complexity. I run across this line
"In the case of the merge-sort algorithm, we get the recurrence equation:
t(n) = b if n < 2
= 2t(n/2) +bn if n >= 2
for b > 0
my response was “how the heck did we know that?!?!”
So i’m wondering if there is a systematic approach, or just a logical way of getting these recurrence relations from the algorithms
can some one explain where the b and the two 2’s come from?
The merge sort algorithm can be summarized as:
There is an O(N) algorithm to merging two arrays of length N, i.e. its complexity is bN for some constant b > 0.
Assuming the complexity of
mergesortis T(N). Since half of N is N/2, we see that:which explains the N ≥ 2 case.
The N < 2 case (the base case where you stop the recursion) is trivial.