递归最糟糕的情况时间复杂性
Worst case time complexity for recursion
int memo[101][101];
int findMinPath(vector<vector<int> >& V, int r, int c) {
int R = V.size();
int C = V[0].size();
if (r >= R || c >= C) return 100000000; // Infinity
if (r == R - 1 && c == C - 1) return 0;
if (memo[r][c] != -1) return memo[r][c];
memo[r][c] = V[r][c] + min(findMinPath(V, r + 1, c), findMinPath(V, r, c + 1));
return memo[r][c];
}
Callsite :
memset(memo, -1, sizeof(memo));
findMinPath(V, 0, 0);
在上面的代码中,最坏情况的时间复杂性是什么?。我了解每个功能都会一次调用其他功能,但是我尚不清楚时间复杂性的计算。
记忆是这里的关键。通常,这将具有指数增长,但是由于先前在memo
中计算结果,因此永远不会执行其他递归步骤,因此将其减少为memo
中的元素数量,因为它是最坏的情况。即 o(101 x 101)
相关文章:
- 具有未知值时的时间复杂性
- 使用堆查找第K个最大元素的时间复杂性
- 将树节点添加到向量向量中的 n 元树遍历的平均和最坏情况时间复杂度是多少?
- 解决这个问题的时间复杂性是多少
- 如果你有一个固定大小的数组,你需要遍历它!n次,使用二进制搜索如何改变时间复杂性
- 对于像C++这样的现实世界语言,时间复杂性有什么一致的定义吗
- 两个嵌套循环的运行时间复杂性:二次型还是线性
- 是平衡二进制树上预购和DFS的时间复杂性
- 带有多个内部回路的循环的时间复杂性
- 列表STL的时间复杂性在一段时间内进行排序
- O(2M N)和O(kN)的时间复杂性
- 映射向量的时间复杂性是多少
- 时间复杂性差异以及如何
- 递归最糟糕的情况时间复杂性
- 可传递值影响递归算法的渐近时间复杂性
- 程序的时间复杂性确定两个字符串是否彼此排列
- 为什么此代码O(n)的时间复杂性
- next_perMuart的时间复杂性在大o符号中
- C 中使用了哪种类型的堆以及STD :: Pirstity_queue的时间复杂性
- 带有两个递归调用的递归算法的时间复杂性