complexity of recursive string permutation function

后端 未结 3 1737
耶瑟儿~
耶瑟儿~ 2020-12-31 01:16

From: Are there any better methods to do permutation of string?

what is the complexity of this function???

void permute(string elems, int mid, int en         


        
3条回答
  •  滥情空心
    2020-12-31 02:00

    long long O(int n)
    {
        if (n == 0)
            return 1;
        else 
           return 2 + n * O(n-1);
    }
    
    int main()
    {
        //do something
        O(end - mid);
    }
    

    This will calculate complexity of the algorithm.

    Actualy O(N) is N!!! = 1 * 3 * 6 * ... * 3N

提交回复
热议问题