Definition of the complexity of time and space

I am having problems defining the complexities of space and time. For example, if I have a tree that has a branching coefficient b and will have no more than depth d, how can I calculate the complexity of time and space? I know that they are O (b ^ d) and O (bd), but my problem is how to get to these values.

Thank!

+3
source share
2 answers

Time

- , , node c ( , c node). , .

nodes          b=2                        b=3
b^0             *                          *
              /   \               /        |        \
b^1          *     *             *         *         *
            / \   / \         /  |  \   /  |  \   /  |  \
b^2        *   * *   *       *   *   * *   *   * *   *   * 
               ...                        ...

, c*b^0 - c. b^1, c*b^1 = c*b . b node , b*b^1 = b^2$ c*b^2.

d b^d, c*b^d. , , c*b^0 + c*b^1 + ... + c*b^d. , :

O(c + c*b + ... + c*b^d) = O(c*b^d) = O(b^d).

: - f(d) = SUM(i=1..d){c*b^i} O(f(d)) = O(b^d).

b=3. * , ? , + , , , .

                    branching factor b = 3                     space
         *             *             *             *             b
       / | \         / | \         / | \         / | \         
      *  ?  ?       *  ?  ?       +  *  ?       +  +  *          b
    / | \         / | \            / | \            / | \      
   *  ?  ?       +  +  *          +  *  ?          +  +  *       b
 / | \               / | \         / | \               / | \   
*  ?  ?             +  *  ?       +  *  ?             +  +  *    b

node, node, , node d. node , node. b , , . , 4 .

, c*b . , node. , . d, c*b*d . , O(c*b*d) = O(b*d).

+6

" ". , " ( )".

b d node , b , b * b = b ^ 2 , b ^ 2 * b = b ^ 3 .. ( 3) 1 + b + b ^ 2 + b ^ 3. . , O (b ^ d) .

, - , , , ( ).

, IDDFS. , O (b ^ d) O (bd), wiki.

+4

Source: https://habr.com/ru/post/1728794/


All Articles