C++ 一个算法来找出它的作用
我有一个算法,我不知道它做什么,它的复杂性是什么,有人能帮我吗C++ 一个算法来找出它的作用,c++,C++,我有一个算法,我不知道它做什么,它的复杂性是什么,有人能帮我吗 PUZZLE (A:int[], L:int, R:int) { // Assume L, R >0 and L <= R If( L = R) Then return A[L]; double Temp1 :=PUZZLE(A,L, (L+R)/2); double Temp2 :=PUZZLE(A, 1 + (L+R)/2,R); If(Temp1 < Temp2) Then return T
PUZZLE (A:int[], L:int, R:int)
{
// Assume L, R >0 and L <= R
If( L = R) Then
return A[L];
double Temp1 :=PUZZLE(A,L, (L+R)/2);
double Temp2 :=PUZZLE(A, 1 + (L+R)/2,R);
If(Temp1 < Temp2) Then
return Temp1;
else Then
return Temp2;
}
计算给定间隔内给定数组的最小值。对我来说,这似乎是前馈的一部分。查看其wiki以获取更多信息此代码计算序列a的子序列中存在的最小值。子序列从索引i开始,在索引j结束。您的算法可以用英文翻译为:
puzzle(A, i, j) :
if the subsequence has only one element :
return this element
min-left is the minimum value present at the first half of the subsequence(it's computed recursively)
min-right is the minimum value present at the second half of the subsequence(it's computed recursively)
return the minimum of min-left, min-right
该算法的复杂度明显高于线性规划。但是,如果你不相信我,我会用主定理为你证明
让TN作为算法的递归。然后:
T(N) = 2T(N/2) =>
T(N) = 2T(N/2) + Theta(1) =>
T(N) = Theta(N) (from the first case of the master theorem, which states
that if f(N) = O(N^logb a-e), for e>0, then the complexity is Theta(N^logb a),
where a=2, b=2, f(N)=Theta(1), and e=1
这似乎不是C++。第一步是找出它是用什么编程语言编写的。@这是微软的目标视觉PASCAL++.@ H2CO3:它是点网!我认为这是最小-最大问题。但不确定,但写错了。