jeudi 9 février 2017

How to determine time complexity of this code?

Vote count: 0

I have just started learning algorithms,

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;
    return V[r][c] + min(findMinPath(V, r + 1, c), findMinPath(V, r, c + 1));
}

I think the answer should be O(RC) but the right answer is O(2^(RC)) I cannot understand why. Please explain.

asked 38 secs ago

Let's block ads! (Why?)



How to determine time complexity of this code?

Aucun commentaire:

Enregistrer un commentaire