Calculating the complexity of algorithm to print all valid (i.e., properly opened and closed) combinations of n-pairs of parentheses
问题 I would like your opinion on the time and space complexity of this algorithm I implemented (in Python) to calculate the complexity of algorithm to print all valid (i.e., properly opened and closed) combinations of n-pairs of parentheses (see all valid combinations of n-pair of parenthesis) def find_par_n(n): s = set(["()"]) for i in range(2, n + 1): set_to_add = set() for str_ in s: set_temp = set() ana = set() for j in range(len(str_) + 1): str_c = str_[0:j] + '(' + str_[j:] if str_c in ana: