【问题标题】:Find time complexity of the recursive program求递归程序的时间复杂度
【发布时间】:2023-03-11 19:10:01
【问题描述】:

谁能帮我理解(逐步)如何找到以下程序的运行时间复杂度?

   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];
}

【问题讨论】:

    标签: algorithm recursion data-structures time-complexity


    【解决方案1】:

    这个过程随着输入呈指数增长,当输入为:'size - r';每次调用 findMinPath 时,输入都会减 1,最终变为 0 并终止。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-27
      • 2013-03-13
      • 2017-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      相关资源
      最近更新 更多