Time complexity of a recursive algorithm

Posted by Passonate Learner on Stack Overflow See other posts from Stack Overflow or by Passonate Learner
Published on 2010-04-25T17:15:11Z Indexed on 2010/04/25 17:23 UTC
Read the original article Hit count: 420

Filed under:
|

How can I calculate the time complexity of a recursive algorithm?

pow1(x,n)
    if(n==0){
        return 1
    }
    else{
        return x * pow1(x, n-1)
    }

pow2(x,n)
if(n==0){
    return 1
}
else if(n is odd integer){
    p = pow2(x, (n-1)/2)
    return x * p * p
}
else if(n is even integer){
    p = pow2(x, n/2)
    return p * p
    }

© Stack Overflow or respective owner

Related posts about c

    Related posts about algorithm