views:

586

answers:

1

I am having some trouble determining space and time complexities. For example, if I have a tree that has a branching factor b and will have at most a depth d, how can I calculate the time and space complexities? I know they are O(b^d) and O(bd) , but my problem is how to get to those values.

Thanks!

+1  A: 

Space complexity amounts to "how much memory will I need to allocate for this algorithm". Time complexity amounts to "how long will it take to execute (in an abstract sense").

A tree with branching factor b and depth d will have one node at its zeroith level, b nodes at its first level, b*b = b^2 nodes at its second level, b^2 * b = b^3 at its third level, etc. In those four levels (depth 3) it has 1 + b + b^2 + b^3. In terms of complexity we only keep around the highest order term and drop any multiplying constants usually. So you end up with a complexity of O(b^d) for space complexity.

Now in time complexity, what your counting is not the number of nodes, but rather the number of loops or recursive calls your algorithm will take to complete (worst case).

I'm going to go out on a limb and assume you're talking about IDDFS. The explanation of where the O(b^d) and O(bd) come from is nicely explained in this wiki article.

vicatcu
He is asking about calculating the time and space complexity of minimax. O(b^d) is the time complexity and the space complexity is O(bd). So this answer doesn't provide much value.
danben
@danben ah, yes i missed that tag.
vicatcu