简体   繁体   English

O(n ^ m)复杂度的递归算法。

[英]Recursive algorithm for O(n^m) complexity.

As far as I know, If I want an iterative algorithm with O(n^m) I just have to use m number of for s on n array elements. 据我所知,如果我想要一个带有O(n^m)的迭代算法,我只需要在n个数组元素上使用mfor s。

Is there any way of building a O(n^m) complexity algorithm (recursive way)? 有没有办法构建O(n^m)复杂度算法(递归方式)? I'd like some explanation on a given algorithm. 我想对给定的算法做一些解释。

This wastes O(n^m) time in a recursive way. 这会以递归方式浪费O(n ^ m)时间。

void waste ( unsigned n, unsigned m ) {
   if ( m ) for ( unsigned i=0; i<n; i++ ) waste(n,m-1);
}

Actually, that was a simple question. 实际上,这是一个简单的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM