我估计时间解决的(复杂性):在递归函数时间复杂度在递归减小了尺寸
// Those methods and list<Element> Elements belongs to Solver class
void Solver::Solve()
{
while(List is not empty)
Recursive();
}
void Solver::Recursive(some parameters)
{
Element WhatCanISolve = WhatCanISolve(some parameters); //O(n) in List size. When called directly from Solve() - will always return valid element. When called by recursion - it may or may not return element
if(WhatCanISolve == null)
return;
//We reduce GLOBAL problem size by one.
List.remove(Element); //This is list, and Element is pointed by iterator, so O(1)
//Some simple O(1) operations
//Now we call recursive function twice.
Recursive(some other parameters 1);
Recursive(some other parameters 2);
}
//This function performs search with given parameters
Element Solver::WhatCanISolve(some parameters)
{
//Iterates through whole List, so O(n) in List size
//Returns first element matching parameters
//Returns single Element or null
}
我首先想到的是,它应该是somwhere各地为O(n^2)。
O(2^n)
但是我认为第二个想法是错误的,因为n被递归调用之间降低:
然后我其中(根据WolframAlpha的)膨胀以想到
T(n) = n + 2T(n-1)
。
我也做了一些大型的基准测试。下面是结果:
N t(N) in ms
10000 480
20000 1884
30000 4500
40000 8870
50000 15000
60000 27000
70000 44000
80000 81285
90000 128000
100000 204380
150000 754390
这是什么语言?当然不是C++。 – SergeyA
很多时候当你降低成本在给定的时间内购买一定数量时,你会以某种形式的日志(n) – 2016-01-22 20:57:46
很难估计知道'WhatCanISolve'的工作原理。即何时可以返回null(w.r.t.列表大小)。 –