Generate all valid combinations of n pair of parentheses Implement an algorithm to print all valid (e.g. properly opened and
  closed) combinations of n pair of parentheses.


Following is my implementation and I think it works. Is the algorithm efficient? Do you see any coding issues?

def compute_all_parens (n, left, right, s):
    if right == n:
        print (s)
        return
    if left &lt; n:
        compute_all_parens(n, left+1, right, s + "(")
    if right &lt; left:
        compute_all_parens(n, left, right+1, s + ")")



# call syntax: compute_all_parens(5, 0, 0, "")
API

The compute_all_parens function requires 4 parameters.
From a user's perspective,
it would be more natural to require only one,
to avoid confusion about what values to pass for the others.
You could use an inner function to encapsulate your implementation details:

def print_all_parens(n):
    def print_parens(left, right, s):
        if right == n:
            print(s)
            return
        if left &lt; n:
            print_parens(left + 1, right, s + "(")
        if right &lt; left:
            print_parens(left, right + 1, s + ")")

    print_parens(0, 0, "")


I also corrected some formatting issues, following PEP8.

Use generators

Instead of printing, it would be nicer to return a generator:

def compute_all_parens(n):
    def compute_parens(left, right, s):
        if right == n:
            yield s
            return
        if left &lt; n:
            yield from compute_parens(left + 1, right, s + "(")
        if right &lt; left:
            yield from compute_parens(left, right + 1, s + ")")

    yield from compute_parens(0, 0, "")


This will give callers the freedom to do whatever they want with the combinations.