Example of Big O of 2^n

后端 未结 7 572
情歌与酒
情歌与酒 2021-01-31 09:11

So I can picture what an algorithm is that has a complexity of n^c, just the number of nested for loops.

for (var i = 0; i < dataset.len; i++ {
    for (var         


        
相关标签:
7条回答
  • 2021-01-31 10:08

    c^N = All combinations of n elements from a c sized alphabet.

    More specifically 2^N is all numbers representable with N bits.

    The common cases are implemented recursively, something like:

    vector<int> bits;
    int N
    void find_solution(int pos) {
       if (pos == N) {
         check_solution();
         return;
       }
       bits[pos] = 0;
       find_solution(pos + 1);
       bits[pos] = 1;
       find_solution(pos + 1);
    }
    
    0 讨论(0)
提交回复
热议问题