The time complexity of the n-ary cartesian product over n sets

2.6k Views Asked by At

Recall that the Cartesian product $A\times A$ is defined as the set $\lbrace (x,y):x\in A ,y \in A \rbrace$ . Thus, if for example, $A=\lbrace 1,2,3 \rbrace$,$A \times A=\lbrace(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)\rbrace$, then the time complexity is $O(n^2 \log n)$, where n refers to the number of members of the set (I presume). But suppose I would like to evaluate $A \times A \times A$ or any finite number of sets in $A \times A \times A$... What would the time complexity be then?

1

There are 1 best solutions below

2
On

I assume the task is generating a string representation of $A^k$.

If $A$ has $n$ elements, we have to list $n^k$ tuples with $k$ components each.

However the size of the numbers themselves grows with growing $n$, needing about $\log_{10}(n) + 1$ digits per component.

So that will give an output of roughly $n^k k \log_{10} n$ digits.