CodeWa!
找到你要的答案

## Q：recurrence relation on a Merge Sort algorithm |
## Q：归并排序算法的递推关系 |

The question is : UNBALANCED MERGE SORT is a sorting algorithm, which is a modified version of the standard MERGE SORT algorithm. The only difference is that instead of dividing the input into 2 equal parts in each stage, we divide it into two unequal parts – the first 2/5 of the input, and the other 3/5. a. Write the recurrence relation for the worst case time complexity of the UNBALANCED MERGE SORT algorithm. b. What is the worst case time complexity of the UNBALANCEDMERGESORT algorithm? Solve the recurrence relation from the previous section. So i'm thinkin the recurrence relation is : T(n) <= T(2n/5) + T(3n/5) + dn. Not sure how to solve it. Thanks in advance. |
问题是： UNBALANCED MERGE SORT is a sorting algorithm, which is a modified version of the standard MERGE SORT algorithm. The only difference is that instead of dividing the input into 2 equal parts in each stage, we divide it into two unequal parts – the first 2/5 of the input, and the other 3/5. a. Write the recurrence relation for the worst case time complexity of the UNBALANCED MERGE SORT algorithm. b. What is the worst case time complexity of the UNBALANCEDMERGESORT algorithm? Solve the recurrence relation from the previous section. So i'm thinkin the recurrence relation is : T(n) <= T(2n/5) + T(3n/5) + dn. Not sure how to solve it. Thanks in advance. |

answer1： | 回答1： |

I like to look at it as "runs", where the ith "run" is ALL the recursive steps with depth exactly i. In each such run, at most
and you will find out that i = log_a(n) - for some base a So, let's be more formal: Claim:
Proof: By induction, at depth 0, all elements are processed exactly once by the first call.
Conclusion: Since at each depth i of the recursion, each element is processed at most once, and the maximal depth of the recursion is logarithmic, we get an upper bound of O(nlogn). We can similarly prove a lower bound of Omega(nlogn), but that is not needed, since sorting is already an Omega(nlogn) problem - so we can conclude the modified algorithm is still Theta(nlogn). If you want to prove it with "basic arithmetics", it can also be done, by induction. Claim: Proof: Base: T(1) = 1 <= 1log(1) + 1 = 1
(**) is because log(3/5)~=-0.22, so 5nlog(3/5) < -n, and 5nlog(3/5) + 2n < n |
我喜欢看它的“运行”，在“运行”是对所有的递归步骤与深度完全一 In each such run, at most
你会发现我= log_a（N）-一些基地 所以，让我们更正式： 索赔：
证明： By induction, at depth 0, all elements are processed exactly once by the first call.
结论： 因为在每一个深度我的递归，每个元素处理的最多一次，和递归的最大深度为对数，我们得到一个上限O（nlogn）。 我们同样可以证明的下限Ω（nlogn），但这是不必要的，因为排序已经是Ω（nlogn）的问题，所以我们可以得出改进的算法仍然是θ（nlogn）。 如果你想用“基本算法”的证明，它也可以做，通过感应。 索赔： 证明： 基地：T（1）= 1 1log <；=（1）+ 1 = 1
（**）是因为日志（3 / 5）~ = -0.22，所以5nlog（3 / 5）& lt；N，和5nlog（3／5）＋2N <；n |

algorithm data-structures mergesort recurrence |