递归思想
拿到一个问题,如何分析问题的递归性质
递归与非递归
递归与动态规划
分析
1.递归问题是否都可以使用动态规划来解决?
满足条件f(n1,n2,n3)=f(n1-k1,n2-k2,n3-k3)
0<=k1,k2,k3 是否就可以通过动态规划来解决递归问题
Meet in the Middle is an algorithmic technique that allows you combine results from two recursive calls efficiently.
Examples where it works:
Find 2 numbers from an array such that their sum is S. Complexity from O(N2) -> O(N)
Knapsack Problem
It works by in the following manner:
Break the given problem into two parts of equal length.
Find solutions to the two parts using brute force.
Now combine the results by picking an element in the first solution set, and searching for a corresponding element in the second solution set.
Notice that the above operation can only be done when merging the two solutions is an aggregate function. (Sum, Count, Max, Min…)
Return the result.
The time complexity of a problem goes from O(Nb) to O(N(b/2)). We see that the time complexity is still exponential, but the exponent is halved.
So, if we have N = 2 and b = 50,
Standard algorithm time: 250 = 12 days!
Meet in the Middle : 225 = 1 Second!
2.
Meet in the middle is a search technique which is used when the input is small but not as small that brute force can be used. Like divide and conquer it splits the problem into two, solves them individually and then merge them. But we can’t apply meet in the middle like divide and conquer because we don’t have the same structure as the original problem.