递归最糟糕的情况时间复杂性

Worst case time complexity for recursion

本文关键字:情况 时间复杂性 递归      更新时间:2023-10-16
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)